0
\$\begingroup\$

I use the unity standard asset components CharacterController and Car and put an empty gameobject onto the car where the camera should be placed when i am inside the car. The empty gameobject is called "Driver". The character controller has an empty called "Head" where its head is.

When i get in the car i perform the following operation

GameObject car = GameObject.Find("Car");  
transform.position = car.transform.Find("Driver").transform.position + Vector3.up*1;
transform.parent = car.transform.Find("Driver").transform;
Camera.main.transform.position = car.transform.Find("Driver").transform.position; 
Camera.main.transform.rotation = car.transform.Find("Driver").transform.rotation; 

and to get out of it, i use the following

GameObject car = GameObject.Find("Car");
transform.position = car.transform.position;
transform.parent = null;
transform.rotation = Quaternion.identity; 
Camera.main.transform.position = transform.Find("Head").transform.position;

My problem is when i get into the car and out again, the character is positioned at the position where i have entered the car, so it doesnt seems to update its position with the car movement.

What am i doing wrong?

Thanks in advance

\$\endgroup\$
  • \$\begingroup\$ Can you debug Log car.transnform.position when entering, and also when exiting, and compare the results? \$\endgroup\$ – Nick Jun 24 '19 at 15:07
1
\$\begingroup\$

Maybe it's simpler if you put Driver object as child of Car in the Hierarchy.

| improve this answer | |
\$\endgroup\$
  • \$\begingroup\$ It sounds from the description as though that's where it is already, unless I'm miseading the question. \$\endgroup\$ – DMGregory Jun 24 '19 at 13:01
  • \$\begingroup\$ Yes, its already child of the car. I ended up disabling the character controller, then move and afterwards enable it again. This way it works. \$\endgroup\$ – MBrain Jun 26 '19 at 1:19

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.