saharan / OimoPhysics

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

Torsional Spring #19

Closed fabiodr closed 2 years ago

fabiodr commented 5 years ago

Hi, Does this new version have a torsional spring (that can restore direction in all axes elastically, by applying torque), or do you know how to apply a force like that?

https://en.wikipedia.org/wiki/Torsion_spring

Thanks!

saharan commented 5 years ago

Hi, Sorry for the delay! You can use GenericJoint in the next version, but it's not available yet in JavaScript port. Instead, RagdollJoint with configured RotationalLimitMotor and SpringDamper may be able to cause the effect required.

var config = new RagdollJointConfig();
// limit all angular axes
config.maxSwingAngle1 = 1e-4;
config.maxSwingAngle2 = 1e-4;
config.twistLimitMotor.setLimits(0, 0);
// make limits elastic
config.swingSpringDamper.setSpring(2, 0.5);
config.twistSpringDamper.setSpring(2, 0.5);
// ... set axes, anchors, and rigid bodies

Hope this helps,

fabiodr commented 5 years ago

No problem and thanks for this guidance!!

Gonna try this soon :) Just wandering if it will perform multiple rotation revolutions instead of taking the shortest rotation path.

The GenericJoint in dev branch can be tested already? Will this joint be the right way to do it?

I also will try something like this, using custom forces, to learn about the topic.

FYI: the effect i want can be seen in this nice demo.

saharan commented 2 years ago

if it will perform multiple rotation revolutions instead of taking the shortest rotation path

Probably you're already aware of the result, but it surely does!