I have a player character, made with the rigidbody character controller, that can walk around and interact with things in my racing game.
You can get out and push the cars.
The problem is you can push the cars around while moving inside them too.
Is there any way around this? I´d like to keep the rigidbody character controller, since it allows many physical things and collisions
Ideally your car controller should be a different one than your player controller, so that you can either deactivate your player controller when driving a car, or make the car the player
This really depends what you need the character to be able to do while in the vehicle. If you don’t need them to move around inside the vehicle here are some things you can try:
- Disabling or removing the rigidbody while the character is driving, then restoring it when they exit the vehicle
- changing the collision layer of the player while driving to prevent collisions between the car and the player
- create a joint between the character and the vehicle, this will lock them to the vehicle as well as disabling collisions between the character and the vehicle by default.
If you do need the character to be able to move around inside the vehicle things become much more complicated as the character will always be able to push the car if they are both rigidbodies. You can try increasing the mass of the car and decreasing the mass of the player, but how effective this is will depend on how you are moving the character.
tldr Realistically you either need to lock the character in place in the vehicle and remove the rigidbody while driving, or not use a rigidbody at all and move the character by other means.
Thanks, I use a joint to keep the player in place when sitting on the driver seat and driving, it´s not a problem there.
But you can work on the car between races, and need to be able to walk around and inside it.
Maybe I need to try a non-physical controller