# How to Make 2D Enemy Slightly Rotate When Moving on the Y Axis

I have a flying enemy that just sorta flies back and forth, and then when the player comes within a certain distance, swoops down towards the enemy, and then moves back to it’s original position. I couldn’t use my Rigidbody to detect velocity, so I made a way of calculating the velocity, basically a coroutine that checks the position, 0.1 seconds later takes down a new position. Then I can use the two positions to calculate velocity.

So, I tried printing a basic oldPos.y - newPos.y, it seems to be working, although the number is small. So I tried changing the angle with,

`````` transform.eulerAngles = new Vector3(0, 0, (10 * (oldPos.y - newPos.y)));
``````

And it doesn’t affect the angle at all, it just remains 0… The only other one that might be affecting it is,

``````        if (isLeft)
{
transform.eulerAngles = new Vector2(0, 0);
}
else
{
transform.eulerAngles = new Vector2(0, 180);
}
``````

But it’s a vector2 so it shouldn’t affect Z right?

Would anyone be able to help with this? Thanks!

`transform.eulerAngles = <something>` is expecting a Vector3. When you pass it a Vector2, that Vector2 gets automatically converted to a Vector3. When a Vector2 is automatically converted to a Vector3, `z` is always set to zero. So yes that code can and is setting your `z` to 0.

Here is the documentation for the implicit Vector2->Vector3 conversion operator: Unity - Scripting API: Vector2.Vector3

Whaat, a vector2 sets the z axis to 0?? I thought the whole point of vector2 was that it left it alone haha, what is the purpose of vector2 then?

I kinda got it working by changing them to vector3s and setting it to transform.eulerangles.z, but it’s very jittery.