Discuss Scratch
- Discussion Forums
- » Suggestions
- » speed variable
- jlnilocalsip
-
100+ posts
speed variable
variable that measures position change in pixels for a given sprite from this frame to the last? might be useful. there isn't an obvious workaround for this afaik
- -gr
-
1000+ posts
speed variable
Maybe something like this?
(position change of [Sprite1 v] in last [1] seconds::sensing)and it could be used like
add (position change of [Sprite1 v] in last [1] seconds::sensing) to [list v]
- CoconutGator
-
1000+ posts
speed variable
I feel like it would look more like this:
(distance to [last position v])OP said it would check from the last frame.
- jlnilocalsip
-
100+ posts
speed variable
Yea this is more what I was envisioning. Ty Maybe something like this?(position change of [Sprite1 v] in last [1] seconds::sensing)and it could be used likeadd (position change of [Sprite1 v] in last [1] seconds::sensing) to [list v]

- -Valtren-
-
1000+ posts
speed variable
you could easily do this by storing the x and y positions of the sprite and the amount of time that passed. speed = distance/time
idk how to find actual distance though. someone else might though
add (x position) to [list v]
add (y position) to [list v]
reset timer
oogly boogly movement stuff :: #7522d7
add (x position) to [list v]
add (y position) to [list v]
set [time v] to (timer)
set [x speed v] to (((item (3 v) of [list v] :: list) - (item (1 v) of [list v] :: list)) / (time))
set [y speed v] to (((item (4 v) of [list v] :: list) - (item (2 v) of [list v] :: list)) / (time))
idk how to find actual distance though. someone else might though
Last edited by -Valtren- (Dec. 12, 2022 15:54:01)
- CrazyScientistTest
-
13 posts
speed variable
easiest workaround: variable that measures position change in pixels for a given sprite from this frame to the last? might be useful. there isn't an obvious workaround for this afaik
set [ x] to (x position)
set [ y] to (y position)
do things that change x & y
set [ x] to ((x position) - (x))
set [ y] to ((y position) - (y))
i also think that his is a really situation specific block
- CrazyScientistTest
-
13 posts
speed variable
easiest workaround: variable that measures position change in pixels for a given sprite from this frame to the last? might be useful. there isn't an obvious workaround for this afaik
set [ x] to (x position)
set [ y] to (y position)
do things that change x & y
set [ x] to ((x position) - (x))
set [ y] to ((y position) - (y))
i also think that his is a really situation specific block
you could easily do this by storing the x and y positions of the sprite and the amount of time that passed. speed = distance/timeadd (x position) to [list v]
add (y position) to [list v]
reset timer
oogly boogly movement stuff :: #7522d7
add (x position) to [list v]
add (y position) to [list v]
set [time v] to (timer)
set [x speed v] to (((item (3 v) of [list v] :: list) - (item (1 v) of [list v] :: list)) / (time))
set [y speed v] to (((item (4 v) of [list v] :: list) - (item (2 v) of [list v] :: list)) / (time))
idk how to find actual distance though. someone else might though
the equation is √(x1-x2)^2+(y1-y2)^2 if youre finding the distance between points (x1, y1) to (x2, y2) in code:
([ sqrt] of (((((x1) - (x2)) * ((x1) - (x2)))) + ((((y1) - (y2)) * ((y1) - (y2)))))
Last edited by CrazyScientistTest (Dec. 14, 2022 00:08:33)
- jlnilocalsip
-
100+ posts
speed variable
Wow that was. Surprisingly easy to work around. Thanks :3
- meepmep_
-
100+ posts
speed variable
you mean like changing how long it takes for something to glide? variable that measures position change in pixels for a given sprite from this frame to the last? might be useful. there isn't an obvious workaround for this afaik
glide (this is your "speed") secs to x: (scouts moms house) y: (tf2 reference go brrr)
- SONIC_ULTIMATE23
-
100+ posts
speed variable
About the workarounds, some of the workarounds could be too advanced for new scratchers so making new blocks would be easier for them.
- cookieclickerer33
-
1000+ posts
speed variable
I wouldn’t say easily tho you could easily do this by storing the x and y positions of the sprite and the amount of time that passed. speed = distance/timeadd (x position) to [list v]
add (y position) to [list v]
reset timer
oogly boogly movement stuff :: #7522d7
add (x position) to [list v]
add (y position) to [list v]
set [time v] to (timer)
set [x speed v] to (((item (3 v) of [list v] :: list) - (item (1 v) of [list v] :: list)) / (time))
set [y speed v] to (((item (4 v) of [list v] :: list) - (item (2 v) of [list v] :: list)) / (time))
idk how to find actual distance though. someone else might though
- Discussion Forums
- » Suggestions
-
» speed variable