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\$
1
  • \$\begingroup\$ Can you debug Log car.transnform.position when entering, and also when exiting, and compare the results? \$\endgroup\$ Commented Jun 24, 2019 at 15:07

1 Answer 1

1
\$\begingroup\$

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

\$\endgroup\$
2
  • \$\begingroup\$ It sounds from the description as though that's where it is already, unless I'm miseading the question. \$\endgroup\$ Commented Jun 24, 2019 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\$ Commented Jun 26, 2019 at 1:19

You must log in to answer this question.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.