Discuss Scratch

DidntMeanToDoThat
Scratcher
500+ posts

How to Make a Sprite Glide in the Direction it's Facing

Hi! I'm wondering if anyone knows a way I can make a sprite glide
 glide () secs to x: (0) y: (0)
in the direction it is facing, like how the
 move () steps 
block works. It would be nice if it worked like this:
glide () secs forward (10) steps

Last edited by DidntMeanToDoThat (Dec. 25, 2024 22:01:48)

FoolsGuld
Scratcher
100+ posts

How to Make a Sprite Glide in the Direction it's Facing

Here is a simple solution, although there are probably better ways to do this

when green flag clicked
create clone of [myself v]
glide (1) secs to x: (destination_x) y: (destination_y)

when I start as a clone
move (steps) steps
set [destination_x v] to (x position)
set [destination_y v] to (y position)
FoolsGuld
Scratcher
100+ posts

How to Make a Sprite Glide in the Direction it's Facing

Better, more complicated solution here:

define Glide (seconds) forward (steps) steps.
if <([abs v] of (direction)::operators) = (90)> then
if <(direction) = (90)> then
glide (seconds) secs to x: ((x position) + (steps)) y: (y position)
else
glide (seconds) secs to x: ((x position) - (steps)) y: (y position)
end
else
glide (seconds) secs to x: ((x position) + (steps)) y: ((y position) + (([tan v] of (direction))* (steps)))
end

an example of this can be found here

Last edited by FoolsGuld (Dec. 25, 2024 22:55:14)

DidntMeanToDoThat
Scratcher
500+ posts

How to Make a Sprite Glide in the Direction it's Facing

Thanks! I somehow didn't think of using clones.

Powered by DjangoBB