C
C#2y ago
Zenternion

UNITY Get Quaterion to rotate towards Object

How do I get (return type) a quaternion to rotate towards an object
4 Replies
mindhardt
mindhardt2y ago
Quaternion Struct (System.Numerics)
Represents a vector that is used to encode three-dimensional physical rotations.
mindhardt
mindhardt2y ago
Is this what you were looking for?
i love cat(mull-rom splines)
be more specific, do you want a quarternion that when applied to what will rotate towards an object the world forward vector? a specific forward vector?
hoggy077
hoggy0772y ago
Like Slerp said, its more dependent on what you're trying to do, but I guess you could do something like
Quaternion dir = Quaternion.LookRotation((TargetObj.position - transform.position).normalized);
transform.rotation = Quaternion.RotateTowards(transform.rotation, dir, speed * Time.deltaTime);
Quaternion dir = Quaternion.LookRotation((TargetObj.position - transform.position).normalized);
transform.rotation = Quaternion.RotateTowards(transform.rotation, dir, speed * Time.deltaTime);
or
Quaternion dir = Quaternion.LookRotation((TargetObj.position - transform.position).normalized);
transform.rotation = Quaternion.Slerp(transform.rotation, dir, speed * Time.deltaTime);
Quaternion dir = Quaternion.LookRotation((TargetObj.position - transform.position).normalized);
transform.rotation = Quaternion.Slerp(transform.rotation, dir, speed * Time.deltaTime);
but without unity in front on me to check those, I'm not 100% they're exactly what you want