Discuss Scratch

nuyouyt2
Scratcher
49 posts

How to make a sprite move towards something

My sprite works by going to an X and Y value, plus the X and Y of the background sprite. I need the sprite to move towards a sprite at 0, 0 by changing the X and Y value of itself, any ideas?
ThreeLived
Scratcher
100+ posts

How to make a sprite move towards something

Well, there are scripts that allow you to get the direction towards positions. Then you might be able to combine it with a move x y block.

this is the point to x y script if you cant use the point towards block.

OR
point in direction (sprite at the center of the screen v)
Then, to move it towards the center, do this:
change x by ((speed) * ([sin v] of (direction)::operators))
change y by ((speed) * ([cos v] of (direction)::operators))
I hope this works for you.
nuyouyt2
Scratcher
49 posts

How to make a sprite move towards something

ThreeLived wrote:

Well, there are scripts that allow you to get the direction towards positions. Then you might be able to combine it with a move x y block.

this is the point to x y script if you cant use the point towards block.

OR
point in direction (sprite at the center of the screen v)
Then, to move it towards the center, do this:
change x by ((speed) * ([sin v] of (direction)::operators))
change y by ((speed) * ([cos v] of (direction)::operators))
I hope this works for you.

This code doesn't seem to work for me, it starts moving in a diagonal direction, and then the X variable and Y Variable get to -20 and stop doing anything.
Any idea what I did wrong?

Edit: i tried making it change the X and Y variables, instead of just the x and y, so itll move in succession to the background map

Last edited by nuyouyt2 (March 13, 2026 18:29:42)

ThreeLived
Scratcher
100+ posts

How to make a sprite move towards something

could you share the project please? also, you may have swapped the x and y variables. ( x - x position is not the same as x position - x )
also, this code may have to be adjusted depending on how your script works. If you, say, set the direction after, you have to account for it.

Powered by DjangoBB