I have been trying to make a box2d body move along a Bezier curve/ arc path. Most of the posts I've seen recommend an approach of manipulating SetLinearVelocity and SetTransform to arrive at an arc-like movement. I don't think testing linear velocity values on a try and error basis would help. I would appreciate any help solving this problem. Thanks.

  • \$\begingroup\$ Do you want a steering approach (where it TRIES to follow a bezier curve but possibly being diverted by other objects) or do you want absolute movement along the path? \$\endgroup\$ – Mikael Högström Sep 7 '12 at 14:07
  • \$\begingroup\$ @MikaelHögström: sorry, I've not been on gamedev for a few days. yes, I am interested in the steering approach. \$\endgroup\$ – allenalex Sep 10 '12 at 14:54
  • 1
    \$\begingroup\$ related stackoverflow.com/questions/12272369/… \$\endgroup\$ – Ciro Santilli新疆棉花TRUMP BAN BAD Dec 16 '17 at 21:06

If you don't need to worry about stuff running into it simply use Body.SetPosition().

If you do then make sure its a kinematic body so its not bumped off course. You should know the time delta the physics engine is going to be updated by. So we can use that to find a direction and velocity that will cause us to be where we want to be after the step has occurred.

I haven't slept in about 24 hours so hopefully I have this right.

Vector3 travelThisStep = (Target - Body.GetPosition()); //How much we need to travel to arrive at our destination
float velocity = travelThisStep.Lenght() / TimeStep; //Distance to travel / Time to travel said distance
Vector3 velocity = travelThisStep * velocity;

  • \$\begingroup\$ sorry I've not been on gamedev for a few days. Thanks for the answer. I am just trying to figure out how it'll work using Cocos2d since that's what I use for game development. That's the main reason I included the Cocos2d tag at first. \$\endgroup\$ – allenalex Sep 10 '12 at 14:45
  • \$\begingroup\$ So your not sure how to fix a Cocos2D sprite over your Box2D body? \$\endgroup\$ – ClassicThunder Sep 10 '12 at 14:47
  • \$\begingroup\$ does Vector3 translate to a b2Vec2 in Box2d? I don't get how the Timestep is calculated, could you explain this a bit further. Because I know the timestep to usually be a function. \$\endgroup\$ – allenalex Sep 10 '12 at 16:23

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.