3

I'm new to using Box2d and really can't find a consistent answer to my question so please excuse me.

I'm writing a game for the iPhone -- who isn't these days -- and I'm using Cocos2d and Box2D. I have objects that move around in the game and I would like to give them a more of a curved path. From my studies I know that I should use body of type b2_kinematicBody which allows me to change the linear velocity every tick and keeps them from colliding with my other flying bodies. I do understand that if I know my current position (x,y) and my next position in the step (x1,y1) I would be able to compute the vector for velocity. Does anybody have a good way to give an object a defined curved path? I'm thinking it has to be some kind of parametric equation.

CodeSmile
  • 64,284
  • 20
  • 132
  • 217
Aaron
  • 157
  • 1
  • 11

2 Answers2

2

Take a look at bezier curves. After curve defenition you can compute the derivative (it's easy for bezier) and use it as a velocity for your body

Andrew
  • 24,218
  • 13
  • 61
  • 90
  • For closer, the first derivative of the bezier curve is working great! Many thanks! – Aaron Oct 26 '11 at 22:38
  • Just to verify I'm going down the right path, to get a constant velocity as the body is moving on the curve I do the follow. After finding velocity vector, I normalize which gives me a constant speed and then multiple by some factor if i want it to move faster on the curve. Does this seem correct for this kind of simulation. – Aaron Oct 27 '11 at 15:56
  • @Aaron: No, it does not. I don't know a simple way for moving with a constant speed along bezier. I suggest you to split the curve programmatically into lines (more lines - more smooth movement). It's easy to control speed if moving on the line – Andrew Oct 27 '11 at 16:43
-1

OH whats the game called? sounds like a good one. have you looked into maybe just doing that in version 2.0

  • I would really like to be able to give a curved path and not just a line. It will increase the complexity by an order of magnitude. – Aaron Oct 07 '11 at 18:19