Game Development Stack Exchange is a question and answer site for professional and independent game developers. Join them; it only takes a minute:

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

I want that an object follows a path, in Peggle game there are some pegs that have movement in a closed path. How can i get the same result? I guess that I can use parametric curve but I need use the velocity and not the position (x, y).

I use NAPE and I have this in my gameloop:

angle = angle + 1*(Math.PI / 180);  
movableBall.position.x = radius * Math.cos(angle)+ h;  
movableBall.position.y = radius * Math.sin(angle)+ k;

It works but I can not control the velocity, each movableBall must have its own velocity. Besides, from docs of NAPE:

"Setting the position of a body is equivalent to simply teleporting the body; for instance moving a kinematic body by position is not the way to go about things.."

I want to use:

movableBall.velocity.x =??  
movableBall.velocity.y = ??  

The final idea is to follow others paths like the Lemniscate of Bernoulli.

share|improve this question
Typically for this site, you don't come here to ask for an answer. You come here to ask how to get an answer. If you want help with the latter we can oblige. But you'll need to tell us what you've tried already and what about it didn't work. Please edit your question with your response. – Byte56 Jun 11 '12 at 5:44
up vote 1 down vote accepted

You can just fake this by finding the next point along the curve for some t increment, calculating the velocity vector to get to that point, and going from there. You'll need to tweak the t increment values to get smooth looking animation, but it'll work. Your objects should not be moving so fast that they'll skip over even sharp turns in your paths, even with the estimates t values.

You can do it the "right way" by actually calculating the desired t value for a given linear speed. Then youll get the exact point to aim for for next frame. You'll need to do some heavy math to solve this though, alon the lines of Personally, I'd go for the hacky estimation solution, since this is a game and not a scientific particle simulation.

Remember, games are rarely about being physically correct; they're about looking correct enough to fool the player into thinking they're physically correct. :)

share|improve this answer

A parametric curve sounds OK. At specific t calculate the x and y coordinate for the object. Then update the object's position. The velocity will control the interval you update this. I think this should make your object follow the parametric curve.

share|improve this answer
@Byte56 thanks for the editing – zinking Jun 11 '12 at 7:10
The object will follow the parametric curve but it will not have constant velocity, unless ||dM/dt|| is constant for every point M on the curve. – sam hocevar Jun 11 '12 at 8:55

Your Answer


By posting your answer, you agree to the privacy policy and terms of service.

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