Discuss Scratch

firesprison
Scratcher
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:
whenclickedforeverwait0.5secspointtowardsmouse pointer

Here, i'll post the link if you cant understand: https://scratch.mit.edu/projects/959451760
Thanks for the support!
Cool_Dude2022
Scratcher
500+ posts

Gradually making sprites turn towards mouse pointer

firesprison wrote:

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:
whenclickedforeverwait0.5secspointtowardsmouse pointer

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

Last edited by firesprison (Feb. 2, 2024 03:56:19)

Cool_Dude2022
Scratcher
500+ posts

Gradually making sprites turn towards mouse pointer

firesprison wrote:

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
On here: https://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:

createcloneofmyselfwhenIstartasaclonehideForeverpointtowardsmouse-pointersetDirection variabletodirectionwhenclickedturndirection-directionvariable/10degrees

Last edited by Cool_Dude2022 (Feb. 2, 2024 04:28:52)

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

Gradually making sprites turn towards mouse pointer

Cool_Dude2022 wrote:

firesprison wrote:

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
On here: https://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:

createcloneofmyselfwhenIstartasaclonehideForeverpointtowardsmouse-pointersetDirection variabletodirectionwhenclickedturndirection-directionvariable/10degrees
This causes a error i like to call “smooth directional clipping”

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
whenclickedforeverchangexbymousex-xposition/10 replace 10 with how slow it should turn. The higher the number the slower it turnschangeybymousey-yposition/10
Then in your tank script just add
whenclickedforeverpointtowardsMouse Tracker
deck26
Scratcher
1000+ posts

Gradually making sprites turn towards mouse pointer

Powered by DjangoBB