Unity - Circular Movement. But without coding anything.
We already created a circular movement behavior with the help of math. But you know what? I don’t like math… Like, at all. And hey, it’s okay to hate it, even as a game developer where you need it sometimes. Anyways, let’s create a circular movement today without using math or code at all!
I. The objective
The objective is pretty clear. We shall create a circular movement without using code or math but with the help of the Animator.
II. Creating the actual behavior
We don’t need assets for this animation. We can simply manipulate the position of an GameObject and Unity will do the rest. Really. It’s as easy as that!
Now, all we need to do is to set the positions we want as keyframes inside the Animator, while in Recording Mode!
But first, let’s break it down:
- We want to create a circular movement.
Let’s say we start at position 0,6,0 and create four keyframes for the circle
- The next point would be -3,3,0
- To get a half-circle, the next position is 0,0,0
- The next position is 3,3,0
- To make the animation a bit more smooth, we create a last keyframe at 0,6,0 once again.
To set a position as keyframe, simply enter the position inside the Inspector and it will be applied for the chosen frame:
Having done that for all five positions we need, your Animator could look like this:
III. The end result
Playing the Animation in Unity will look like this:
Yes, that’s all you need to do!
Trust me, I was absolutely mind-blown when a GameDevHQ coach showed me that this was possible to create without any code! The Animator really seems to be very powerful and it really seems like it will save you time and frustration in many situations. I went through the pain of coding that behavior. 17 lines of code in two hours. That could have been just some minutes… Life of a developer I guess :D
Thanks for your time and interest!
Catch you next time again!