Discuss Scratch

Whitepatchwastaken
Scratcher
100+ posts

Mouse-pointer rotation shenanigans

How do I make a sprite rotate towards my mouse pointer at a set speed, kinda like a Dartling Gunner from Bloons TD? Thanks in advance!

the small text ruse was a…….. DISTACTION⠀⠀⠀⠀⠀⠀i HAVE the kumquat
Whitepatch!
Did you mean: griffpatch
sometimes Putting effort into my posts since 2022
I program games and then never share them
I crawl around Help with Scripts when I feel like giving/getting help
Spentine
Scratcher
1000+ posts

Mouse-pointer rotation shenanigans

Ok… so… are you familiar with trigonometry…? Because you're going to have to find the vector of the relative positions and move it like that…

pls dont comment “a” on my profile

also my connect 4 AI
JimboJones47
Scratcher
100+ posts

Mouse-pointer rotation shenanigans

Here is one way. You could look at how this was done. This has a block that runs without screen refresh. It sets one variable to the current direction the sprite is facing, then rotates to the direction of the mouse pointer and gets that direction. Finally, it rotates back to the direction it was before. Since this is done without refresh you won't see the sprite jerk back and forth.

Once it has those 2 angles, it takes the difference, and figures out if it should rotate left or right. Finally, it limits the amount of rotation by the rotation speed variable, and turns.

https://scratch.mit.edu/projects/639482566/

deck26
Scratcher
1000+ posts

Mouse-pointer rotation shenanigans

Whitepatchwastaken
Scratcher
100+ posts

Mouse-pointer rotation shenanigans

JimboJones47 wrote:

Here is one way. You could look at how this was done. This has a block that runs without screen refresh. It sets one variable to the current direction the sprite is facing, then rotates to the direction of the mouse pointer and gets that direction. Finally, it rotates back to the direction it was before. Since this is done without refresh you won't see the sprite jerk back and forth.

Once it has those 2 angles, it takes the difference, and figures out if it should rotate left or right. Finally, it limits the amount of rotation by the rotation speed variable, and turns.

https://scratch.mit.edu/projects/639482566/

This helps a lot, thanks for the help!

the small text ruse was a…….. DISTACTION⠀⠀⠀⠀⠀⠀i HAVE the kumquat
Whitepatch!
Did you mean: griffpatch
sometimes Putting effort into my posts since 2022
I program games and then never share them
I crawl around Help with Scripts when I feel like giving/getting help

Powered by DjangoBB