I have a 3rd person skateboarding character (imagine Tony Hawks) whose rotation I wish to set at the top of a half pipe (so that they launch straight “up” and land back down on the pipe, without moving either forward or backwards). I’m doing this as, for small half pipes, some forward momentum is maintained so they hit the top and keep moving forward. Not ideal!

Fig 1 - Skateboarder and halfpipe.
In order to set the correct rotation (as if the player is riding an invisible wall aligned with the half pipe), I figure the players local x rotation should be 270.

**Fig 2 - Halfpipe with “wall”. No matter the angle player goes up halfpipe, they should behave as if riding this (nonexistant) wall **
To do this, I have a collider/trigger set up at the lip of the pipe, with an OnTriggerEnter() calling this code:
if (coll.gameObject.tag == "Player")
{
Vector3 newEulerAngles = new Vector3(270,
coll.gameObject.transform.rotation.eulerAngles.y,
coll.gameObject.transform.rotation.eulerAngles.z);
float speed = 100000; // want this to be instant
float step = speed * Time.deltaTime;
coll.gameObject.transform.rotation =
Quaternion.RotateTowards(coll.gameObject.transform.rotation,
Quaternion.Euler(newEulerAngles), step);
}
When trying this however, the y and z rotation is set to zero, every time.
Fig 3 - Approaching pipe at an angle
Fig 3 - On trigger, player rotation is snapped to (270, 0, 0), despite only x being altered
I’ve tried various methods and they all behave this way, for example the simpler script:
if (coll.gameObject.tag == "Player")
{
Vector3 newEulerAngles = new Vector3(270,
coll.gameObject.transform.rotation.eulerAngles.y,
coll.gameObject.transform.rotation.eulerAngles.z);
coll.gameObject.transform.rotation = Quaternion.Euler(newEulerAngles);
}
I’ve done some looking around and my best guess is this has something to do with Gimbal locking, but I could be way off. If anyone can point out why the player is snapping to this angle and ignoring the previous y, z values I’d love to learn!