- Home /
RotateTowards and Rotate Conflict
I have an airplane that rotates towards a vector using Vector3.RotateTowards. The problem is that it does not look realistic because the plane does not roll/bank into the turns. I have used Vector3.Rotate on the z axis by itself to get the desired roll, however, when I try RotateTowards then Rotate, or vice versa, RotateTowards seems to cancel out any rotation I had on the z axis. My C# code:
// Direction towards target
Vector3 targetVect -= transform.position;
targetVect.Normalize();
float angle = Mathf.Deg2Rad * turnRate * Time.deltaTime; // Angle to rotate
transform.forward = Vector3.RotateTowards(transform.forward, targetVect, angle, 0);
transform.Rotate(0, 0, turnRate * Time.deltaTime, Space.Self); // Roll the plane
Is there a way that I can have my plane rotate towards another vector while also changing the roll of the plane.
One easy way to do it is to separate it into a parent and a child object, where you only bank with with one and rotate towards with the other.
Your answer
Follow this Question
Related Questions
Enemy follow/chase behaviour glitching when using rotateTowards 0 Answers
an object rolls forward and turn right at the same time... 1 Answer
Controlling the speed of Vector3.RotateTowards 0 Answers
Rotate player to joystick sprite location 0 Answers
Making a ball roll and keeping the axis? 2 Answers