Do you want help with velocity-based movement or making a sprite move along a pre-defined path?
Offline
MoreGamesNow wrote:
Do you want help with velocity-based movement or making a sprite move along a pre-defined path?
I want to make my sprite move along a pre-defined path.
Offline
AgentCNF wrote:
MoreGamesNow wrote:
Do you want help with velocity-based movement or making a sprite move along a pre-defined path?
I want to make my sprite move along a pre-defined path.
And how are you defining the path? With a mathematical formula?
Offline
MoreGamesNow wrote:
AgentCNF wrote:
MoreGamesNow wrote:
Do you want help with velocity-based movement or making a sprite move along a pre-defined path?
I want to make my sprite move along a pre-defined path.
And how are you defining the path? With a mathematical formula?
I don't know! Thats what I'm asking. How do I make a sprite move in a curved path?
Offline
you may want to use a quadratic formula, they make curved graphs
Offline
Essentially, a "curve" is defined by a mathematical function. You can figure out the function a number of ways but the most popular way is probably this:
Choose three points for a sprite to pass through (beginning, middle, and end of the path). Solve the equation (y position) = a(x position)^2 + b(x position) + c using the three points. In other words, if the first point is (3,5), one of your equations is 5 = a(3^2) + b(3) + c. If the middle point is (6,3), your second equation is 3=a(6^2)+b(6)+c
Once you have your three equations you can solve for variables a, b, and c (Do you know algebra? If you have difficulty solving for three variables using three equations, I may be able to find a generic formula for the variables based on the three points).
Now you have y=3(x^2)-5(x)+3 (for example). Now you have a path that your sprite can move along. Just make the y position a function of the x position:
when gf clicked forever change x by (1) set y to ((((3)*((x position)*(x position)))-((5)*(x position)))+(3))I hope that made sense
Offline
MoreGamesNow wrote:
Essentially, a "curve" is defined by a mathematical function. You can figure out the function a number of ways but the most popular way is probably this:
Choose three points for a sprite to pass through (beginning, middle, and end of the path). Solve the equation (y position) = a(x position)^2 + b(x position) + c using the three points. In other words, if the first point is (3,5), one of your equations is 5 = a(3^2) + b(3) + c. If the middle point is (6,3), your second equation is 3=a(6^2)+b(6)+c
Once you have your three equations you can solve for variables a, b, and c (Do you know algebra? If you have difficulty solving for three variables using three equations, I may be able to find a generic formula for the variables based on the three points).
Now you have y=3(x^2)-5(x)+3 (for example). Now you have a path that your sprite can move along. Just make the y position a function of the x position:when gf clicked forever change x by (1) set y to ((((3)*((x position)*(x position)))-((5)*(x position)))+(3))I hope that made sense
I don't understand that at all, cause im in 7th grade, so I don't know a whole lot of algebra. Instead of that, can you tell me if there's a way for me to draw a path and my sprite go along the path that I made? That may be easier... I don't know.
Last edited by AgentCNF (2013-01-22 16:28:42)
Offline
Like this or with an invisible curve?
Offline
MoreGamesNow wrote:
Like this or with an invisible curve?
Preferably invisible. But I don't want people playing to draw it. I want to draw it in the studio and then when something happens, it moves along the line. like this:
when [space v] key pressed forever follow line end
Offline
If you don't want to use a mathematical function (which could admittedly be unwieldy) You could store positions in a list and retrace yours steps that way. With enough points it would look smooth.
Take a look at this. In the finished project you would not have the dots and only use a pre-made list, but I let you plot the dots to help demonstrate the concept.
Last edited by MoreGamesNow (2013-01-22 18:15:28)
Offline