x


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.

before.jpg (260.2 kB)
after.jpg (325.6 kB)
more ▼

asked Jun 11 '12 at 12:11 AM

chuckbergeron gravatar image

chuckbergeron
17 1 3

Here's a video showcasing the strange behaviour: http://youtu.be/403zIiyieS4

The first bit shows with Moving 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!

Jun 11 '12 at 03:26 AM chuckbergeron
(comments are locked)
10|3000 characters needed characters left

1 answer: sort newest

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.

more ▼

answered Jun 11 '12 at 01:18 AM

aldonaletto gravatar image

aldonaletto
41.5k 16 42 197

Thanks for the reply, Aldo. There's no script that I know of zeroing the localRotation, and I'm using the default CharacterMotor.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.

Jun 11 '12 at 02:10 AM chuckbergeron

Video's finally ready! http://www.youtube.com/watch?v=403zIiyieS4 Also, this is in Unity 3.5.0f2 Pro with default character controller.

Jun 11 '12 at 03:27 AM chuckbergeron

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!

Jun 11 '12 at 04:46 AM chuckbergeron

Glad to know it worked!

Jun 11 '12 at 01:52 PM aldonaletto
(comments are locked)
10|3000 characters needed characters left
Your answer
toggle preview:

Up to 2 attachments (including images) can be used with a maximum of 524.3 kB each and 1.0 MB total.

Follow this question

By Email:

Once you sign in you will be able to subscribe for any updates here

By RSS:

Answers

Answers and Comments

Topics:

x2171
x1281
x180
x138
x20

asked: Jun 11 '12 at 12:11 AM

Seen: 464 times

Last Updated: Jun 11 '12 at 01:52 PM