- Home /
2D circular movement
Hello all, I want to make a Player object( initially located at position (0,0 - 2D game) to move around in a circular motion using x = radius cos(theta) and y = radius sin(theta), keeping radius fixed(radius = 5) , automatic and continually moving the object round. I looked through some tutorials. I did some code, which shows the result in logs to be fine but in the UI the object does not move. Below is the code that i used for Update method. What is wrong in it ?
***
Thanks in advance
unity-2d.png
(20.0 kB)
Comment
Answer by BastianUrbach · Jul 18, 2018 at 04:35 PM
//Update is called once per frameWhat that means is that the game displays the scene, runs the Update function, then displays the changed scene and so on. To animate something, you need to make small incremental changes to the scene in each Update call (Currently you're rotating by 360° for each frame). One easy way to do this is to use Time.time (the time since the game started in seconds) in Update. Scratch the loop, Unity takes care of repeatedly calling Update. Instead of the loop variable i, you put Time.time and you're done.