Discuss Scratch

Eloki_
Scratcher
39 posts

How to track x velocity

How would I go about tracking the current speed of a sprite on the x axis?
bcs320jn
Scratcher
100+ posts

How to track x velocity

What do you mean?
benk_b4b
Scratcher
100+ posts

How to track x velocity

Here's a very simple velocity script:
when flag clicked
set [x velocity v] to [0]
go to x:[0] y:[0]
forever
if <key [left arrow v] pressed> then
change [x velocity v] by [-1]
end
if <key [right arrow v] pressed> then
change [x velocity v] by [1]
end
change x by (x velocity)
set [x velocity v] to ((x velocity)*(0.9))
end
Eloki_
Scratcher
39 posts

How to track x velocity

I want to measure the current speed a sprite is moving left or right

Last edited by Eloki_ (Jan. 3, 2022 22:55:42)

benk_b4b
Scratcher
100+ posts

How to track x velocity

0.9 is a friction value (how fast it slows down - the closer to 1, the slower it decelerates, the closer to 0, the faster it decelerates)
benk_b4b
Scratcher
100+ posts

How to track x velocity

Yes, and in this script, that would be x velocity.
If, for example, x velocity is -5, that would mean the velocity to the left is 5. If x velocity were 8, it would mean the velocity to the right is 8.
Eloki_
Scratcher
39 posts

How to track x velocity

This is a good movement script however what I want is to track the speed of a sprite on the x axis, not to create a fluid movement script.
benk_b4b
Scratcher
100+ posts

How to track x velocity

What do you mean speed? Here, x velocity is the speed. Can you show me an example? (for example the project you need this for)?
benk_b4b
Scratcher
100+ posts

How to track x velocity

Do you just mean how much it moved left or right each frame?
Eloki_
Scratcher
39 posts

How to track x velocity

The script you provided is changing the x velocity directly, however the script I want is to measure the x velocity at which a sprite is currently moving without messing with the movement of a sprite.

yes, how much it moves left/right

Last edited by Eloki_ (Jan. 3, 2022 23:02:09)

benk_b4b
Scratcher
100+ posts

How to track x velocity

That isn't technically x velocity. But if that's what you are looking for, then try this:
when flag clicked
forever
set [x movement v] to ((x position)-(old x position))
set [old x position v] to (x position)
end
Eloki_
Scratcher
39 posts

How to track x velocity

Yes that works thanks.
benk_b4b
Scratcher
100+ posts

How to track x velocity

No problem!
feet_lol_pete
Scratcher
5 posts

How to track x velocity

also guys if u want the speed of the x to go to only 6 the you set the part on the set velocity x to .8571428599

Powered by DjangoBB