Take the 2-minute tour ×
Game Development Stack Exchange is a question and answer site for professional and independent game developers. It's 100% free, no registration required.

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:

//circunference   
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
1  
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

2 Answers 2

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 https://www.math.lsu.edu/~madden/M2057s2004/speed.pdf. 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
1  
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

 
discard

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.