"attach character (with character controller) to vehicle with physics(wheel colliders,rigidbody)" (21938)

Hi there

I have a vehicle, that is able to drive (wheel colliders/physics)

And I have a 3rd person Character that can move.

I disable the movement of the character, when I click on the vehicle and enable the vehicles driving system. I also parent the vehicle to the character.

My problem is that the Character does not move with the vehicle. If I delete the character controller of the character, then it does move with the vehicle…

What could I do?

  • Remove/Add the character controller?
  • Glue the character “better” to the vehicle?

2 Answers

2

I don’t think you can move / ‘glue’ an object with a character controller on by physics, as in joints etc. I think it’s always setting it’s position or something.

Have you tried prefabbing your whole character? Instantiate it to start with,

clone = Instantiate(mycharacter, myposition, myrotation);
then destroy it
Destroy(clone);
when getting in the vehicle, then instantiate it offset to the vehicle when you get out? You could replace the character with another prefab of one without the character controller if you needed the model to be viewable, or if you have an animation of it getting in or something.

I guess I have too much stuff assigned to the character. So I can not destroy/clone it that simple. But it's propably the only way I can do this, you are right. I tried disabling the character controller but with no success, as it does not derive from MonoBehaviour it does not have the enabled property.

Instantiating my character is terribly slow. If it's not possible to instantiate the character faster, then this is not the solution yet.

Instantiating took so long, because my character controller system was coupled too tight to the prefab I used for the player. I'll mark it as answer.

except its not. If i look, its there and clicking on it makes it say its not missing.

i have an issue somewhat related to this but the vehicle is parented to the character and idk how to unparent it without messing up a game