- Home /
Changing the parent transform of the First Person Controller
Allo there. I'm having a strange issue when attaching a First Person Controller as a child of another transform, namely an elevator.
The parentTransform is rotated 180 degrees so as soon as the function fires, the First Person Controller rotates around 180 degrees to match it's new parent's localspace. Same thing happens in reverse, the FPC flips a 180 when it becomes relative to worldspace again.
The code looks a lil' something like this:
private var parentTransform : Transform;
function Start () {
parentTransform = transform.parent;
}
function OnTriggerEnter( collided : Collider ) {
if ( collided.gameObject.tag == "Player" )
collided.transform.parent = parentTransform;
}
I know it works like a charm when the parentTransform isn't rotated, but I'll need to set up multiple elevator instances, each with their own unique position & rotation.
Thanks!
Edit: Added Photos as visual-aide.
[1]: http://answers.unity3d.com/storage/temp/1206-before.jpg
[1]: http://answers.unity3d.com/storage/temp/1207-after.jpg
Here's a video showcasing the strange behaviour: http://youtu.be/403zIiyieS4
The first bit shows with $$anonymous$$oving Platform enabled, no child/parenting going on, and jittery movement.
After that, with child/parenting via script and the strange rotation issue happening in the Aux elevator instance (rotated 180 degrees).
Lastly, I go over to the working elevator (rotated 0 degrees) and it's smooth as silk.
Cheers!
Answer by aldonaletto · Jun 11, 2012 at 01:18 AM
That's a weird thing: I tested the First Person Controller and a moving platform rotated 180 degrees, but nothing wrong happened - the player entered and exited the trigger without changing its rotation, as expected. I tried all the modes in the Character Motor / Moving Platform fields, and nothing changed. Could you have some other script zeroing the FPC localRotation? Or are you using another control script (not CharacterMotor.js)? By the way, if you're using the standard CharacterMotor, there's no need to child the character to the platform - the script already provides control for moving platforms - just let let Character Motor / Moving Platform / Enabled checked in the Inspector, which by the way is the default.
Thanks for the reply, Aldo. There's no script that I know of zeroing the localRotation, and I'm using the default Character$$anonymous$$otor.js w/ default settings. However, the framerate goes jittery if I don't child the FPC to the moving platform. It's nice and smooth as a child, and works like a charm on the main elevator (no instance rotation). I'm uploading a video to YouTube to give a better idea of what's going on.
Video's finally ready! http://www.youtube.com/watch?v=403zIiyieS4 Also, this is in Unity 3.5.0f2 Pro with default character controller.
You were right. The 180 degrees thing doesn't seem to matter when I pull the elevator out into a brand new test project, and use complete default First/Third Person Controllers. Cheers!