Discuss Scratch

jlnilocalsip
New Scratcher
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
Scratcher
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
Scratcher
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
New Scratcher
100+ posts

speed variable

-gr wrote:

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]
Yea this is more what I was envisioning. Ty
-Valtren-
Scratcher
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

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
Scratcher
13 posts

speed variable

jlnilocalsip wrote:

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
easiest workaround:

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
Scratcher
13 posts

speed variable


jlnilocalsip wrote:

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
easiest workaround:

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

-Valtren- wrote:

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

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

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
New Scratcher
100+ posts

speed variable

Wow that was. Surprisingly easy to work around. Thanks :3
meepmep_
Scratcher
100+ posts

speed variable

jlnilocalsip wrote:

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
you mean like changing how long it takes for something to glide?
glide (this is your "speed") secs to x: (scouts moms house) y: (tf2 reference go brrr)
SONIC_ULTIMATE23
Scratcher
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
Scratcher
1000+ posts

speed variable

-Valtren- wrote:

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

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
I wouldn’t say easily tho

Powered by DjangoBB