Hello, What I’m trying to achieve with my player controls (in a flying game) is to tilt the player side to side using mouse controls. I have done that successfully but my hang up is leveling the player back out. I need it to level out constantly and not just when the mouse has no input, it takes constant movement to tilt.
I have already prototype this out in blender using python. Tilting was simply done by assigning the rotation value to an axis and then aligning the up axis to a vector:
player.alignAxisToVect([0.0,0.0,1.0], 2, 0.1)
that is what axis to align, which vector, and over how much time.
In the following code written in C# “tiltPoint” refers to an object that rotates with the player rig but does not rotate on the z-axis and “mainP” is the main parent of the rig which all the other movement is applied to (and what I want to align with, no need to restrict any axis). I’m using a Quaternion Slerp for rotation. As written it tilts the player just fine but still doesn’t level out, I don’t understand why.
yRotation += Input.GetAxis("Mouse X");
//tilt the player
float oldTiltX = tiltPoint.transform.eulerAngles.x;
float oldTilty = tiltPoint.transform.eulerAngles.y;
player.transform.rotation = Quaternion.Slerp(Quaternion.Euler(new Vector3(oldTiltX, oldTilty, yRotation * 5)), mainP.transform.rotation, Time.deltaTime * 6);
As I understand it “(Quaternion.Euler(new Vector3(oldTiltX, oldTilty, yRotation * 5)” should be my from and “mainP.transform.rotation” should be my to. Yet it never levels out but tilts just fine. Is there a better way to do this or am I making a simple mistake?
Any help is appreciated!