Get the Vector3/float needed for an object to face a target transform.

I’m currently trying to setup a rotation system using rootmotion so I just need the float needed for the transform to face a target. Is this possible?

Vector3 newDirection = Vector3.RotateTowards(transform.forward, target.position - transform.position, Time.deltaTime, 0.0f);

I found this but I don’t really need the time.deltaTime.

What do you mean by ‘the float’? Like an angle? Just look through the docs for Vector3 and Quaternion and you’ll find examples on that.

Otherwise you need be more clear.

1 Like

I believe it’s the angle but it’s not using Vector3.dot
currentAngle = Vector3.Dot(transform.forward,Vector3.Normalize(target.transform.position - transform.position));

This will return the same value whether it needs to turn right or left. I need the actual float in order to set the animator value so I can have a turn animation play based on which direction and how much it needs to rotate.

Well… Vector.Dot doesn’t give an angle.

Like I said, look at the docs. There are some very obviously named methods that give you the result you want: Unity - Scripting API: Vector3