- Home /
Rotate Object in a single frame
How would i rotate an object to face another in a single frame
Vector3 lookat = (Vector3 (100,1,100) - transform.position).normalized;
transform.rotation = Quaternion.Slerp (transform.rotation, Quaternion.LookRotation (lookat), speed * Time.deltaTime);
the code above takes frames to complete, when i increase the speed it is off
More Info:
what i am doing is resetting the gameobjects rotation to face a target once it is respawned
ins$$anonymous$$d of setting the rotation manually, have you considered using transform.LookAt(object.transform)? Also, you could try transform.forward = mesh.bounds.center - object.gameObject.mesh.bounds.center
I edited my 1st post (Vector3 (100,1,100), ins$$anonymous$$d of target.position) as my target is a vector3 coordinate
also i tried using lookAt, it didnt work.
In that case, try doing a Quaternion.Euler ins$$anonymous$$d of a Slerp. Isn't one of the built in function of a Slerp the fact that it eases the rotation?
If you do transform.localRotation = Quaternion.Euler(Vector3(calculate this)); then it should rotate it in one frame.
Answer by TheKusabi · Aug 15, 2013 at 02:39 PM
Try this:
Vector3 lookat = (Vector3 (100,1,100) - transform.position).normalized;
transform.rotation = Quaternion.LookRotation (lookat);
Your answer