- Home /
Rotate relative to Parent
I am attempting to make the upper body of the player always face the target. This is the code i have so far:
private void LateUpdate()
{
RotationDirection = target.position - transform.position;
qTo = Quaternion.LookRotation(RotationDirection);
transform.rotation = qTo * transform.rotation;
}
This script is attached the the upper spine.
however when the player gameobject rotates, it messes up. Like it when the target is behind the player, it reverses the direction and acts like the target is in front of the player and aims forward. I have tried changing the rotation to LOCAL by changing it to Transform.LocalRotation, but that did not work. I have tried moving the multiplication of Transform.rotation to before qTo But that did not work.
Answer by ozavegames · Aug 31, 2019 at 06:03 PM
You can try LookAt method for this. https://docs.unity3d.com/ScriptReference/Transform.LookAt.html
Your answer
Follow this Question
Related Questions
Flip over an object (smooth transition) 3 Answers
How to set a single-axis rotation and not change the others axes 1 Answer
Trouble with Camera Rotation Math 2 Answers
Weird shake when I try to rotate player according to Virtual Cameras rotation. 0 Answers
Transform rotation and position on key input: rotation only working the first time 2 Answers