Discuss Scratch
- Discussion Forums
- » Help with Scripts
- » Gradually making sprites turn towards mouse pointer
- firesprison
-
19 posts
Gradually making sprites turn towards mouse pointer
Hey there, I am firesprison.
Im trying to make a tank, where the cannon points towards the mouse faster than the actual base.
I've figured out how to make the base point towards the mouse slower than the cannon, but its WAY too choppy.
What I have right now:
Here, i'll post the link if you cant understand: https://scratch.mit.edu/projects/959451760
Thanks for the support!
Im trying to make a tank, where the cannon points towards the mouse faster than the actual base.
I've figured out how to make the base point towards the mouse slower than the cannon, but its WAY too choppy.
What I have right now:
when green flag clicked
forever
wait (0.5) secs
point towards [mouse pointer v]
end
Here, i'll post the link if you cant understand: https://scratch.mit.edu/projects/959451760
Thanks for the support!
- Cool_Dude2022
-
500+ posts
Gradually making sprites turn towards mouse pointer
Hey there, I am firesprison.
Im trying to make a tank, where the cannon points towards the mouse faster than the actual base.
I've figured out how to make the base point towards the mouse slower than the cannon, but its WAY too choppy.
What I have right now:when green flag clicked
forever
wait (0.5) secs
point towards [mouse pointer v]
end
Here, i'll post the link if you cant understand: https://scratch.mit.edu/projects/959451760
Thanks for the support!
Instead of using “wait 0.5 secs” change it to a lower number, like 0.1 seconds.
I just figured out what you meant, I'll try to make something.
Last edited by Cool_Dude2022 (Feb. 2, 2024 03:24:48)
- firesprison
-
19 posts
Gradually making sprites turn towards mouse pointer
I dont think so you understood what I meant, I mean that I wanted a smooth and slow turning speed but thanks for your effort
Nevermind
Nevermind
Last edited by firesprison (Feb. 2, 2024 03:56:19)
- Cool_Dude2022
-
500+ posts
Gradually making sprites turn towards mouse pointer
On here: I dont think so you understood what I meant, I mean that I wanted a smooth and slow turning speed but thanks for your efforthttps://en.scratch-wiki.info/wiki/List_of_Block_Workarounds go down to the “Point Towards Mouse-Pointer” work around and you can try using that to help with your code. Best of luck!
EDIT: I've thought of a new idea, create a clone and make it invisible. You can then point the clone towards the mouse and set the direction that the clone is facing to a variable. You can then subtract the direction that the box is facing from the variable and now it will slowly turn toward the mouse:
create clone of [myself v]
when I start as a clone
hide
Forever
point towards [mouse-pointer v]
set [Direction variable v] to (direction)
End
when green flag clicked
turn ccw (((direction) - (direction variable)) / (10)) degrees
Last edited by Cool_Dude2022 (Feb. 2, 2024 04:28:52)
- Cool_Dude2022
-
500+ posts
Gradually making sprites turn towards mouse pointer
I've posted a code idea above, you might have to play around with it, but that should at least work. It might be inverted, but you should know how to fix that. If you don't, just message me here and I'll fix it.
- HundenBasse
-
100+ posts
Gradually making sprites turn towards mouse pointer
This causes a error i like to call “smooth directional clipping”On here: I dont think so you understood what I meant, I mean that I wanted a smooth and slow turning speed but thanks for your efforthttps://en.scratch-wiki.info/wiki/List_of_Block_Workarounds go down to the “Point Towards Mouse-Pointer” work around and you can try using that to help with your code. Best of luck!
EDIT: I've thought of a new idea, create a clone and make it invisible. You can then point the clone towards the mouse and set the direction that the clone is facing to a variable. You can then subtract the direction that the box is facing from the variable and now it will slowly turn toward the mouse:create clone of [myself v]
when I start as a clone
hide
Forever
point towards [mouse-pointer v]
set [Direction variable v] to (direction)
End
when green flag clicked
turn ccw (((direction) - (direction variable)) / (10)) degrees

When it reaches 180 then the next step is to go to -180. But when smoothing it like this it will cause it to go down from 180 to -180 gradually making it seem like its rotation the wrong way.
This is what you should do instead.
Create a new sprite called Mouse Tracker.

Add this code to it
when green flag clickedThen in your tank script just add
forever
change x by (((mouse x) - (x position)) / (10)) // replace 10 with how slow it should turn. The higher the number the slower it turns
change y by (((mouse y) - (y position)) / (10))
end
when green flag clicked
forever
point towards [Mouse Tracker v]
end
- deck26
-
1000+ posts
Gradually making sprites turn towards mouse pointer
https://scratch.mit.edu/projects/55006278 might help.
- Discussion Forums
- » Help with Scripts
-
» Gradually making sprites turn towards mouse pointer