DanielChappuis / reactphysics3d

Open source C++ physics engine library in 3D
http://www.reactphysics3d.com
zlib License
1.5k stars 218 forks source link

question: how would you set up a car controller #119

Closed mokalux closed 4 years ago

mokalux commented 4 years ago

hello and thank you very much for making reactphysics3d.

I am using this physics engine in gideros. I have a car vehicle and I wonder what would be the best/easiest way to control that car? Using joints? attaching several (4) fixtures to the body? I tried so many things that I am out of ideas right now. Is applying force and torque enough? Thank you for your help. PS: I did not know where to post so I did it here (please remove if inappropriate).

DanielChappuis commented 4 years ago

Thanks for your feedback.

Currently, there is no support for vehicles in the library. I plan to work on this in the future.

I am not sure if it can really be done using joints only.

slojanko commented 1 year ago

Hey,

just a followup to this. I'm making a GameMaker wrapper for ReactPhysics3D and implemented a buggy vehicle. It is possible to do it with multiple fixed/hinge joints, althought either my understanding of them is incorrect or the vehicle just needs tweaking.

I have a center rigidbody (chassis), then 4 rigidbodies attached with fixed joints to the center of the chassis. The front two rigidodies get two extra bodies attached with hinge joints for turning support, axis is vertical.

I then attach two more rigidbody to the back two rigidbodies and two more rigidodies to the front two wheels. This represents the tires rotating when moving.

I'm not sure how hinge joints work in practice, if the mass of one rigidbody massively outweighs the other one, it should rotate the lighter one instead, but I get weird behavior because of the friction coefficient which makes the tires extremely hard to turn.

Also the simulation is not stable, resulting in the vehicle getting stuck even at very high solver iterations (20/10).

Will continue changing parameters, but maybe an approach that doesn't rely on giving wheels torque for moving would be better.