This is a read-only archive of the old Scratch 1.x Forums.
Try searching the current Scratch discussion forums.

#1 2013-01-21 17:21:50

AgentCNF
Scratcher
Registered: 2012-08-27
Posts: 21

How do I make a sprite move along a curved pattern?

I know how to make sprites move up, down, and diagonal, but I want to make my sprite move in a curve, not a straight line!


Go St. Louis Cardinals!!! I Hate The Cubs!

Offline

 

#2 2013-01-21 17:54:33

MoreGamesNow
Scratcher
Registered: 2009-10-12
Posts: 1000+

Re: How do I make a sprite move along a curved pattern?

Do you want help with velocity-based movement or making a sprite move along a pre-defined path?


http://images2.layoutsparks.com/1/218929/rubiks-cube-animated-rotating.gif
"Cogito ergo sum" --  I think, therefore I am

Offline

 

#3 2013-01-21 17:59:10

AgentCNF
Scratcher
Registered: 2012-08-27
Posts: 21

Re: How do I make a sprite move along a curved pattern?

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.


Go St. Louis Cardinals!!! I Hate The Cubs!

Offline

 

#4 2013-01-21 20:38:18

MoreGamesNow
Scratcher
Registered: 2009-10-12
Posts: 1000+

Re: How do I make a sprite move along a curved pattern?

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?


http://images2.layoutsparks.com/1/218929/rubiks-cube-animated-rotating.gif
"Cogito ergo sum" --  I think, therefore I am

Offline

 

#5 2013-01-21 20:41:50

AgentCNF
Scratcher
Registered: 2012-08-27
Posts: 21

Re: How do I make a sprite move along a curved pattern?

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?


Go St. Louis Cardinals!!! I Hate The Cubs!

Offline

 

#6 2013-01-22 09:38:07

Tbtemplex97
Scratcher
Registered: 2011-11-12
Posts: 100+

Re: How do I make a sprite move along a curved pattern?

you may want to use a quadratic formula, they make curved graphs


Online Status: http://blocks.scratchr.org/API.php?action=onlineStatus&user=Tbtemplex97
Darkspace Coming Soon!, Try the Singleplayer Demo

Offline

 

#7 2013-01-22 11:55:04

AgentCNF
Scratcher
Registered: 2012-08-27
Posts: 21

Re: How do I make a sprite move along a curved pattern?

Tbtemplex97 wrote:

you may want to use a quadratic formula, they make curved graphs

I don't know what that is. D:


Go St. Louis Cardinals!!! I Hate The Cubs!

Offline

 

#8 2013-01-22 14:00:50

MoreGamesNow
Scratcher
Registered: 2009-10-12
Posts: 1000+

Re: How do I make a sprite move along a curved pattern?

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  hmm


http://images2.layoutsparks.com/1/218929/rubiks-cube-animated-rotating.gif
"Cogito ergo sum" --  I think, therefore I am

Offline

 

#9 2013-01-22 16:18:41

AgentCNF
Scratcher
Registered: 2012-08-27
Posts: 21

Re: How do I make a sprite move along a curved pattern?

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  hmm

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)


Go St. Louis Cardinals!!! I Hate The Cubs!

Offline

 

#10 2013-01-22 17:23:45

MoreGamesNow
Scratcher
Registered: 2009-10-12
Posts: 1000+

Re: How do I make a sprite move along a curved pattern?

Like this or with an invisible curve?


http://images2.layoutsparks.com/1/218929/rubiks-cube-animated-rotating.gif
"Cogito ergo sum" --  I think, therefore I am

Offline

 

#11 2013-01-22 17:45:46

AgentCNF
Scratcher
Registered: 2012-08-27
Posts: 21

Re: How do I make a sprite move along a curved pattern?

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


Go St. Louis Cardinals!!! I Hate The Cubs!

Offline

 

#12 2013-01-22 18:15:05

MoreGamesNow
Scratcher
Registered: 2009-10-12
Posts: 1000+

Re: How do I make a sprite move along a curved pattern?

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)


http://images2.layoutsparks.com/1/218929/rubiks-cube-animated-rotating.gif
"Cogito ergo sum" --  I think, therefore I am

Offline

 

Board footer