Hi there guys
I’m busy implementing a system where my player can climb into a car and drive it. I have managed to do the following, but now I’m stuck:
Create a trigger around the car
User press “u” key to climb on car
Then I parent the Car with the player, thus the player becomes a child (this is not working well)
Disable the Character Motor script for the player
This is working sortoff. The player get’s parented and it follows the car when I drive it, but it seems to be very unstable.
Can anyone give some advise here, thanks!
Does the player have a collider associated with it that’s interacting with the collider(s) associated with the vehicle?
Hi Jesse
The player is the standard FPS controller, so there isn’t any collider that I’m aware of. I have in the mean time been messing around with the idea of rather instantiating the player and removing it when the player climb into the car. This also works pretty well. All I have to do now is to assign all variables when I instantiate the player.
I don’t have Unity open right now, but if you’re talking about the character controller, it does have a collider associated with it (a capsule). Without testing it I’m not sure how it would interact with other colliders in the scenario you described, but I imagine it could lead to undesirable behavior.
In any case, I’d probably just destroy and re-instantiate the player object as needed (or replace it with another object while the player is in the vehicle). That’s how I’ve handled this in the past, at least.
Hi Jesse
You were correct. Destroying and instantiating the player is working just fine.
Thanks once again, you are always willing to help!
i have the same problem could anybody share the code here (the destroying andinstantiating
There’s no ‘the code’, because how it should be coded depends on the context and how things are set up.
But, the Destroy() and Instantiate() functions are fairly straightforward to use (see the docs for details). You’ll need to call Destroy() with the player game object as the argument when the player gets into the vehicle, and then call Instantiate() to recreate the player object when the player gets out of the vehicle. If there’s state associated with the player that needs to persist, you’ll need to use a different method, or find a way to store the state when the player object is destroyed, and restore it when the player object is recreated.
Hi Funky
I’m implementing a different system of moving one camera between the player and the car. I will post a quick tutorial on YouTube when I’m done. Basically it is a matter of doing something like this:
playerCamera.transform.parent = GameObject.FindWithTag("Player").transform;
That will attach the camera to the Player GameObject
not a bad idea
but is it possible to set the whole character true or false via script??
thx thats what i looked for