2

How can one make a box2d body move in a spiral motion? I believe it will require applying some force but I am not sure how. I would appreciate any assistance.

oopology
  • 1,072
  • 1
  • 10
  • 19

2 Answers2

0

You can chain joints together using intermediate invisible bodies. Pin a body at the center to the ground with a revolute joint, and a prismatic from that body to the real one. Two joints = two motors = two controllable degrees of freedom.

MrWaqasAhmed
  • 1,479
  • 12
  • 12
  • I would really appreciate it if you could explain this further, possibly with a code sample. Thanks. – oopology Apr 17 '13 at 07:05
0

You'll have two forces, a tangential force, and a radial force.

The tangential force accelerates the body around the center.

The radial force accelerates the body towards or away from the center.

radialVector = (objectPosition - spiralCenter).normalize();
tangentialVector = radialVector.perpendicularVector();

forceTangential = tangentialForceMagnitude * tangentialVector;
forceRadial = radialForceMagnitude * radialVector;
force = forceTangential + forceRadial;
object.applyForce(force);

The specific values for your force magnitudes will determine the behaviour of the spiral; things like wether it's an inward or outward motion, and how fast.

I answered a related question about making a whirlpool/vortex: SO: How to create whirlpool/vortex effect?

Community
  • 1
  • 1
DylanVann
  • 483
  • 5
  • 9