3
\$\begingroup\$

I have a 2d physics engine, with three boxes: "body", "left wing" and "right wing". The wing boxes are connected to the body using a hinge joint. The physics world has no gravity.

enter image description here

I'm attempting to rotate the wings around their hinge connection, as if the joint is motorized but I'm not exactly sure how to achieve that. If I exert force with a downward vector on the center of the wings, the body itself flies down. This is undesirable. With an actual hinge motor, only the wings will rotate about the hinge, affecting the body only when they hit it.

Which forces should be added to the wings, and at which origin points?

I'm using Phaser.io, with P2.js physics, but the question is platform-agnostic.

\$\endgroup\$

2 Answers 2

1
\$\begingroup\$

Apply two forces in opposite directions. The one at the far end of the wing turns it. The other at the hinge - applied to the wing not the body at that point - zeros out the first so the whole craft doesn't move.

Note that the far-end force is perpendicular to the line from the hinge to where it is applied. That's not essential, but it won't accomplish anything useful to have it at some angle.

Pair of forces applied to wing block

\$\endgroup\$
0
\$\begingroup\$

This exact same question from the exact same person has already been answered on another site.

http://www.html5gamedevs.com/topic/8824-p2-motorized-hinge-joint/

You can use the motor in the joint to create the rotation around the joint: To make things simpler, how about enabling the motor on the constraint?

constraint.enableMotor();
constraint.setMotorSpeed(1);

Documentation: http://schteppe.github.io/p2.js/docs/classes/RevoluteConstraint.html

Demo: http://schteppe.github.io/p2.js/demos/car.html

\$\endgroup\$

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .