Character standing on a moving vehicle

Post Reply
kander
Posts: 5
Joined: Tue Apr 27, 2021 2:08 am

Character standing on a moving vehicle

Post by kander »

Hey all,

I have a player controlled character (rigid body) which is moved by setting its velocity before each physics update. I would like the player to be able to stand and walk around on top of a moving vehicle.

I have tried increasing the friction between the vehicle and the player, and also setting the player's velocity to match that of the vehicle, but when the vehicle is under a lot of acceleration (start, stop, turning) the player slides around too much.

I have another idea, and that is to constrain a dummy object to the top of the vehicle at the players last position, and then for each impulse that is applied to this dummy object during simulation step, I apply the same to the player object. However, I haven't figured out how to retrieve this information yet.

Please let me know if you have any other ideas.
kander
Posts: 5
Joined: Tue Apr 27, 2021 2:08 am

Re: Character standing on a moving vehicle

Post by kander »

I have found the results are really good if I turn up friction to the max. Howver, this means my character is stuck to to anything it touches and cannot move. It looks like I can use the contactAddedCallback to customize the friction between the player and the vehicle. I will try and see If I can apply the friction selectively.
User avatar
drleviathan
Posts: 849
Joined: Tue Sep 30, 2014 6:03 pm
Location: San Francisco

Re: Character standing on a moving vehicle

Post by drleviathan »

This is really hard to do. By tweaking the friction and damping and adding special "am I standing on a vehicle?" logic to your character you might get satisfactory results with only one "world" if your vehicle moves slowly, however such a system will eventually fail as vehicle velocities increase. BTW, you probably want to try setting character damping to zero when standing on the vehicle if you haven't already. Damping is a non-physical feature of Bullet but is useful for introducing global energy loss to help things settle down.

I've never actually tried it but: I believe better results can be obtained by using a second "world" simulation. When the character walks onto the vehicle you would spin up a second simulation, remove the character from first and add it to the second. In the second (vehicle-local) simulation the vehicle's collision shape is a static "ground". The character can walk around and you use the acceleration of the vehicle in the first simulation to dynamically set the local gravity of the second simulation. In physics terms: the character is standing in an non-inertia reference frame... when the vehicle accelerates. Of course, if you need the character to interact with any other first-world objects besides the vehicle then you'd have to add collision proxies in the second simulation and things start to get really complicated if you need those objects to be dynamically moved by the character.
kander
Posts: 5
Joined: Tue Apr 27, 2021 2:08 am

Re: Character standing on a moving vehicle

Post by kander »

drleviathan wrote: Tue Apr 27, 2021 2:09 pm I've never actually tried it but: I believe better results can be obtained by using a second "world" simulation. When the character walks onto the vehicle you would spin up a second simulation, remove the character from first and add it to the second. In the second (vehicle-local) simulation the vehicle's collision shape is a static "ground". The character can walk around and you use the acceleration of the vehicle in the first simulation to dynamically set the local gravity of the second simulation. In physics terms: the character is standing in an non-inertia reference frame... when the vehicle accelerates. Of course, if you need the character to interact with any other first-world objects besides the vehicle then you'd have to add collision proxies in the second simulation and things start to get really complicated if you need those objects to be dynamically moved by the character.
Thanks drleviathan. I have considered the two world approach, but have not tried it yet. You highlight the difficulty with this approach; objects interacting between worlds. One idea I had was to revert back to world 1 player rigid body when a large enough collision occurs, but keeping them in sync looks tricky. Maybe if I always update world 2 first, I can then pass on the total impulse to the world 1 bodies each time step.

I'm also wondering now if a weak velocity constraint (one iteration of solving) would work. Unfortunately I don't think bullet provides a velocity constraint (constrain relative velocity of 2 bodies). I wonder how difficult it would be to implement 🤔
kander
Posts: 5
Joined: Tue Apr 27, 2021 2:08 am

Re: Character standing on a moving vehicle

Post by kander »

The slider constraint looks like it can be used as a velocity constraint. I will play around with it first.
kander
Posts: 5
Joined: Tue Apr 27, 2021 2:08 am

Re: Character standing on a moving vehicle

Post by kander »

Another update.

It looks like setting velocity of player to vehicle + player movement acctually works waaay better than I first thought. My current solution involves setting player position and adding a positional constraint only when the relative movement between the vehicle and the player is very small.
chineseoldghost
Posts: 3
Joined: Tue Jun 04, 2013 6:58 am

Re: Character standing on a moving vehicle

Post by chineseoldghost »

maybe try first,calc the correct force to rigidbody,then calc vehicle local space move force to rigidbody
you can look the raycast vehicle ,how to calculate wheel fraction force .like the force by different velocity of two rigidbody,fixed force like this will solve the character on a moving vehicle
Post Reply