- Home /
Maintain world rotation on parenting to another object
Hi,
I have a player controller which can enter a vehicle. Trigger colliders automatically set the player controller's parent as the vehicle on entry and set the player's parent to root on exit, so that when the vehicle moves across rough terrain or banks or rolls, the player controller is not thrown around.
Here's the problem I'm experiencing:
If the vehicle is rotated away from Vector3.forward, or zero rotation or whatever you want to call it (I'm not the most experienced programmer, sorry!), the player jumps to a new world rotation when they enter or exit the vehicle.
E.G. Vehicle is facing 90 degrees in the Y axis. Player enters the vehicle facing 0 degrees in Y axis. On entry, the player suddenly jumps to facing 90 degrees world rotation (or 0 degrees local rotation in the vehicle.)
Basically, I need to preserve the player's world rotation on entry/exit from the vehicle. At the moment, upon being made a child of the vehicle, the player's world rotation is copied to its local rotation in the vehicle, causing the sudden rotation if the vehicle is facing anywhere other than dead ahead.
I know I can make the vehicle a child of an empty game object and make that the parent of the player, but introduces more issues than it solves for me, so what I'm looking for is a programming solution to this issue - I need a way to make the world rotation of the unparented player the local rotation of the parented player.
Does that make sense?! Sorry if it doesn't - it's been a long day.
Any help appreciated.
Your answer
Follow this Question
Related Questions
Setting rotation of child GameObject 1 Answer
Issues Rotating an object 0 Answers
Keep Rotation on one Axis but aligning others to Parent 0 Answers
Local child rotation and transform.LookAt 2 Answers
Child versus Parent rotations 3 Answers