saharan / OimoPhysics

A cross-platform 3D physics engine
MIT License
863 stars 68 forks source link

Question: What is the equivalent of setLinearFactor() in bullet physics? #18

Closed MiloHX closed 5 years ago

MiloHX commented 5 years ago

Hi! Thanks for the wonderful physics engine! I got a question: if I want to lock a specific axis of an object, in bullet I can use setLinearFactor() and set that axis to 0.0. In Oimo I found that there is setRotationFactor() for rotation, but I didn't find the equivalent for location. May I know what is the best way to achieve this?

Regards Milo

saharan commented 5 years ago

Hello, thanks for using the library! As you say, I haven't implemented setLinearFactor yet so there is no equivalent function in release 1.2.0. But there are a few ways to lock a specific axis of an object, and I recommend the following one:

  1. create a static rigid body to which the object (that you want to lock an axis) will be locked
  2. create a GenericJoint that connects the static rigid body and the object. By default, two objects are completely stuck and they cannot move or rotate along each other
  3. unlock all the rotational and translational limits except the axis you want to lock

Please note that simply assigning a constant to the object's location and velocity every frame will not work correctly, as it does not perform as a "physical constraint."

I hope this helps :)

MiloHX commented 5 years ago

I think I got the answer, case closed & thank you!