Best way to have cars and driver

Hi, So im learning unity by simply trying to make different parts which could be included in a game. So just now im trying to have a car and a player, which i have but I want the player controls to stop working and the player to ‘disappear’ when pressing E next to the car, and when E is pressed again the car controls stop working and the player appears again.

So I am trying to figure out the best way to do this. I was thinking I could have a collision box next to the car, player enters it presses E and the player is toggled to inactive. However this didn’t really work cause I could not recall it (since the update function was not being called, because its inactive, I believe) So, Would destroying the player and re-spawning it be the best option? Or is there another way I am not thinking of?

I suppose destroying and recreating the player would work.

However, back to disabling your player and it not working for you because it was disabled. I would think a good way to tackle that situation would be to have a check for the ‘E’ key pressed in a script elsewhere (obviously not on the inactive player game object) :wink:
From there, you check if it’s ‘E’ and the player is in “Car Mode”, then exit from that, and re-enable the player and its controls.

That sounds sensible. :slight_smile:

mm Yeah I never thought of checking E from another script once the player in inactive. I will give that a try, Thanks :slight_smile:

No problem :slight_smile:

So I decided to stay with the setactive method, but rather than putting the script on another object, I simply created a parent and disabled the children. So now im trying to work out the best way to handle the player being at the correct position when the player ‘leaves the car’ (since the player is slower than the car, he reappears behind the car) .

Is there a way to attach the two objects for the amount of time the players is inactive for, or I know there is a transform function, would using that somehow be the best way?

I did try to destroy the object, but couldnt figure out how to Instantiate it properly. :frowning:

Edit : I know why the instantiate is not working. Same reason as before, the script isnt running when the object is destroyed, Would need to have that on another object too

you could have an empty game object - nothing but a transform - as a child of the car. You could reference that as the “exit” spot, I suppose. Then , when you re-activate the player, set their position equal to that of the exit spot.