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?
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.