Sines & Cosines Can Do Magic
If you haven't realized the capability of sines and cosines in making objects move in game then you are in for a treat.
In order to make the objects move you just have to set the x position & y position respectively.
In order to make the objects move you just have to set the x position & y position respectively.
Here are some of the things we will be making:
First we just make the ball travel in a circle.
The 'itrValue' is some value that keep changing every frame like Time.timeSinceLevelLoad
Position in x-axis : Sin(itrValue) * radius
Position in y-axis : Cos(itrValue) * radius
Now we will make it tilt towards a side:Position in y-axis : Cos(itrValue) * radius
Position in x-axis : Sin(itrValue) * radius
Position in y-axis : Cos(itrValue + offset) * radius
We will now make it move in a flower petal path:Position in y-axis : Cos(itrValue + offset) * radius
Position in x-axis : Sin(itrValue) * (radius + Cos(itrValue* frequency)
Position in y-axis : Cos(itrValue) * (radius + Cos(itrValue* frequency)
Position in y-axis : Cos(itrValue) * (radius + Cos(itrValue* frequency)
Now a random-esque path, useful when object need to move in a way that looks semi-random like the movement of a swarm of mosquitoes:
Position in x-axis : Sin(itrValue) * (radius + Cos(itrValue + Sin(itrValue * frequency))
Position in y-axis : Cos(itrValue) * (radius + Cos(itrValue+ Cos(itrValue* frequency))
Position in y-axis : Cos(itrValue) * (radius + Cos(itrValue+ Cos(itrValue* frequency))
You can get the Unity package HERE.
If you just want the source code, you can get it HERE.
For more Unity development tutorials go HERE.