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

#1 2013-01-31 16:37:47

CAA14
Scratcher
Registered: 2013-01-14
Posts: 1000+

How to get the velocity of a sprite

Hi,

I'm curious to know how you can get the speed or velocity of a sprite.

Regards,

CAA14

Offline

 

#2 2013-01-31 16:44:42

ErnieParke
Scratcher
Registered: 2010-12-03
Posts: 1000+

Re: How to get the velocity of a sprite

CAA14 wrote:

Hi,

I'm curious to know how you can get the speed or velocity of a sprite.

Regards,

CAA14

Well, this is actually quite simple, if you do you're movement one way. First, you'll need to create two variables for a sprite called "X Velocity" and "Y Velocity". Then, just do this to move your sprite:

when gf clicked
forever
 change x by (X Velocity)
 change y by (Y Velocity)

Now that you have that built in, you know a sprites speed up/down (Y Velocity) and left/right (X Velocity). Also, if you want to know it's forward speed, just use this:

([sqrt v] of (((X Velocity) * (X Velocity)) + ((Y Velocity) * (Y Velocity))))

If you don't use X Velocity and Y Velocity, then things are going to get harder, which is why it's recommended that you do use X Velocity and Y Velocity in projects where you need to track speed or in situations where you want more realistic physics.

I hope that this helps!

Last edited by ErnieParke (2013-01-31 16:45:46)


http://i46.tinypic.com/35ismmc.png

Offline

 

#3 2013-01-31 16:55:10

CAA14
Scratcher
Registered: 2013-01-14
Posts: 1000+

Re: How to get the velocity of a sprite

Hi,

Thanks for responding.

Thanks again.  smile
What actually made me wonder about that was looking at your project.  smile
One reason i ask is that i would also like to make a forever running game to the right, and i need to know how to scroll and to get velocity for impact of things.



Thanks again,

CAA14

Offline

 

#4 2013-01-31 17:01:21

ErnieParke
Scratcher
Registered: 2010-12-03
Posts: 1000+

Re: How to get the velocity of a sprite

CAA14 wrote:

Hi,

Thanks for responding.

Thanks again.  smile
What actually made me wonder about that was looking at your project.  smile
One reason i ask is that i would also like to make a forever running game to the right, and i need to know how to scroll and to get velocity for impact of things.



Thanks again,

CAA14

So you're making a scrolling game using velocities, right? Just to make sure, you do now how to do this?

And again, your welcome.  wink


http://i46.tinypic.com/35ismmc.png

Offline

 

#5 2013-01-31 17:11:05

CAA14
Scratcher
Registered: 2013-01-14
Posts: 1000+

Re: How to get the velocity of a sprite

Well, you see, I am also right now trying to learn Java, and I'm kind of waiting on scratch 2.0. The java stuff is being very uncooperative and scratch 2.0 has several bugs still.

So, I'm not yet making anything, except the very basics of my pacman game.
You see, i don't yet know trigonometry or geometry, so I don't know how to come up with the formulas most other people do. That's why i am asking about using velocity because i need to know how to do things in scratch like you can do in java, like "getHeight" and stuff. I want to be able to "getSpeed" and use that to determine if the player crashes or is just blocked.

Thanks again, and could you please post that article about scrolling you were talking about? I looked at one and it was confusing...

CAA14

Offline

 

#6 2013-01-31 18:38:35

ErnieParke
Scratcher
Registered: 2010-12-03
Posts: 1000+

Re: How to get the velocity of a sprite

CAA14 wrote:

Well, you see, I am also right now trying to learn Java, and I'm kind of waiting on scratch 2.0. The java stuff is being very uncooperative and scratch 2.0 has several bugs still.

So, I'm not yet making anything, except the very basics of my pacman game.
You see, i don't yet know trigonometry or geometry, so I don't know how to come up with the formulas most other people do. That's why i am asking about using velocity because i need to know how to do things in scratch like you can do in java, like "getHeight" and stuff. I want to be able to "getSpeed" and use that to determine if the player crashes or is just blocked.

Thanks again, and could you please post that article about scrolling you were talking about? I looked at one and it was confusing...

CAA14

Interesting; I'm also learning Java.

Anyway, here's the link to the article. If you don't understand it, then you can always ask me to explain scrolling.  wink

Last edited by ErnieParke (2013-01-31 18:39:22)


http://i46.tinypic.com/35ismmc.png

Offline

 

#7 2013-01-31 20:04:36

CAA14
Scratcher
Registered: 2013-01-14
Posts: 1000+

Re: How to get the velocity of a sprite

Thanks!

BTW, how are you learning java? What compiler are you using?
Also, as an update, since my java projects are having trouble, i am making a never ending run game. I am trying to figure out animating it.  smile

So, this article will come in useful, because the floor is the main thing not finished...


Thanks again,

CAA14

Offline

 

#8 2013-01-31 20:36:46

CAA14
Scratcher
Registered: 2013-01-14
Posts: 1000+

Re: How to get the velocity of a sprite

Well, i did not think ahead, i am not using that velocity thing this time, since the sprite never actually moves.  smile

Well, lets see if i understand that article, if i have problems, I'll post.


Thanks again,

CAA14

Offline

 

#9 2013-01-31 21:11:33

CAA14
Scratcher
Registered: 2013-01-14
Posts: 1000+

Re: How to get the velocity of a sprite

Ok, it's official, i need help. D smile

I will (hopefully) upload a beta version of my project tomorrow and post the problems.

Regards,

CAA14

Offline

 

#10 2013-01-31 21:27:31

ErnieParke
Scratcher
Registered: 2010-12-03
Posts: 1000+

Re: How to get the velocity of a sprite

CAA14 wrote:

Thanks!

BTW, how are you learning java? What compiler are you using?
Also, as an update, since my java projects are having trouble, i am making a never ending run game. I am trying to figure out animating it.  smile

So, this article will come in useful, because the floor is the main thing not finished...


Thanks again,

CAA14

Well I am using TextPad, and a teacher at my school is teaching me java, though only the basics. I'll be getting into the "advanced" material next year…

And are you sure you don't want to use X Velocity? This way you can change speeds very easily and realistically, leading to better movement in a lot of situations. Also, you don't need the sprite to be actually moving to be able to use velocities. For example, in quite a few scrollers, the player sprite doesn't move, though it has some sort of velocity.

Anyway, I'll stop by your project tomorrow.  wink

Last edited by ErnieParke (2013-01-31 21:28:00)


http://i46.tinypic.com/35ismmc.png

Offline

 

#11 2013-02-01 11:13:07

CAA14
Scratcher
Registered: 2013-01-14
Posts: 1000+

Re: How to get the velocity of a sprite

That's realy cool to here about the Java stuff.  smile
I'm also just learning the basics, but i am having tech problems with my compiler that i can't figure out.

Well, if i know how to use velocity, i would.....

I'm going to post it soon,

Regards,

CAA14

Offline

 

#12 2013-02-01 12:06:41

CAA14
Scratcher
Registered: 2013-01-14
Posts: 1000+

Re: How to get the velocity of a sprite

Okay, it's uploaded here.

I listed the goals, so it's all there.

Thanks again,

CAA14

Offline

 

Board footer