- Home /
Problems with pushing rigidbodies while standing on them
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
Answer by AbandonedCrypt · Feb 15, 2021 at 01:33 PM
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
Answer by MUG806 · Feb 15, 2021 at 01:47 PM
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.
Answer by Artoodiitoo · Feb 15, 2021 at 02:15 PM
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 :(
You could try making the car kinematic while the player is working on it, so that it cant move. Or creating a joint between the car and the world.
Well I can´t really do that, since I need the car to be physical, like in a race after crashing and the car is on fire, and you need to get out of the car and behind the safety fence, but other cars in the race can still (accidentally) crash into your wreck.
I tried making the physic material of my player collider bit more slide-y, and disabling running while inside the car, that helps some but the bug still exists. It´s probably more a nuisance if you don´t have handbrake on than a cheat, so that might do for it :D
I made a system that detects when player is inside vehicles, and changes the physics material for the player collider to zero friction, so I can use $$anonymous$$imal forces to move the character inside. Seems to work and has smaller effect on moving the car around when inside