Discuss Scratch

philipaj
Scratcher
13 posts

how do you make a sprite go to the mouse pointer?

I don't know how to explain this… like when you move your mouse the sprite should move a little bit to the mouse pointer but not all the way there similar to this-
when green flag clicked
forever
go to x: ((mouse x) / (50)) y: ((mouse y) / 50))
end

but the problem is it can only work in the center (x=0 y=0)

Last edited by philipaj (May 13, 2024 07:53:49)

philipaj
Scratcher
13 posts

how do you make a sprite go to the mouse pointer?

the above code was supposed to be
when green flag clicked
forever
go to x: ((mouse x) / (50)) y: ((mouse y) / (50))
end
JBeanBean
Scratcher
17 posts

how do you make a sprite go to the mouse pointer?

Im not completely sure what your asking, but if it only works in the center, you can try dividing it by a smaller number like
when green flag clicked
forever
go to x: ((mouse x) / (5)) y: ((mouse y) / (5))
end

hi i like coding
when green flag clicked::#FF8C1A
if [why is this a dropdown v] then::#40BF4A
broadcast (key clicked::#4CBFE6)::#D65CD6
end::#40BF4A
end::#FF6680
deck26
Scratcher
1000+ posts

how do you make a sprite go to the mouse pointer?

Better to point towards the mouse and move n steps. In your code if the mouse moves towards the sprite the sprite will move away from the mouse. Also you're always moving to a point near 0,0 - the maximum mouse x can be is 240 so you're always going to move the sprite to an x position between -5 and 5 (roughly).
philipaj
Scratcher
13 posts

how do you make a sprite go to the mouse pointer?

r u saying smtn like this-
when green flag clicked
forever
point towards [mouse pointer v]
move (10) steps
end
if u meant this this doesn't work cause it continues to go toward it… i want it to go just a bit

Last edited by philipaj (May 14, 2024 06:41:48)

P-P-C
Scratcher
21 posts

how do you make a sprite go to the mouse pointer?

If you want to have a smooth movement try this
change x by ((((mouse x) - (x position)) / (5)))
change y by ((((mouse y) - (y position)) / (5)))
deck26
Scratcher
1000+ posts

how do you make a sprite go to the mouse pointer?

So are you saying you only move once each time the mouse moves? You still don't want to be dividing the mouse x or y by a number - the important value is the mouse x minus the player's x to get the distance between them (same for y).
philipaj
Scratcher
13 posts

how do you make a sprite go to the mouse pointer?

philipaj wrote:

I don't know how to explain this… like when you move your mouse the sprite should move a little bit to the mouse pointer but not all the way there similar to this-
when green flag clicked
forever
go to x: ((mouse x) / (50)) y: ((mouse y) / 50))
end

but the problem is it can only work in the center (x=0 y=0)
[/quote]


this is the result what I want to get but at a different x,y position (this only works at about x=0,y=0)

Last edited by philipaj (May 14, 2024 14:41:52)

philipaj
Scratcher
13 posts

how do you make a sprite go to the mouse pointer?

(i still am new to this coding in discussion forums so don't expect too much)

Powered by DjangoBB