1
\$\begingroup\$

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.

\$\endgroup\$
1
  • 1
    \$\begingroup\$ 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. \$\endgroup\$
    – House
    Commented Jun 11, 2012 at 5:44

2 Answers 2

1
\$\begingroup\$

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. :)

\$\endgroup\$
1
\$\begingroup\$

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.

\$\endgroup\$
1
  • 1
    \$\begingroup\$ 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. \$\endgroup\$ Commented Jun 11, 2012 at 8:55

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .