Discuss Scratch

ThatOneCoder435
Scratcher
100+ posts

How do I make a sprite smoothly point towards the mouse (instead of using the snappy point towards mouse block)?

I'm working on a shooter, and I wan't my player to smoothly (but quickly) point towards the mouse. Is there a way to do this?
I've tried this script, but when I face at the -180 to 180 mark, it rotates the opposite way:
 
forever
set mdir
turn cw ((.5) * ((mouse dir) - (direction))) degrees
end
define set mdir
set [prev dir v] to (direction)
point towards [mouse pointer v]
set [mouse dir v] to (direction)
point in direction (prev dir)
I can't find any other solutions, is there any others?
RT_Borg
Scratcher
1000+ posts

How do I make a sprite smoothly point towards the mouse (instead of using the snappy point towards mouse block)?

Hi ThatOneCoder435,

I think my Smooth Rotate tool will do what you're looking for.

Tool: Smooth Rotate Toward
https://scratch.mit.edu/projects/690745166
Some notes about they work: https://scratch.mit.edu/discuss/post/6298326/

(They handle the -180/180 split properly.)

You can use either of the backpackable custom blocks in the first sprite (Rotate Toward).

– RT_Borg
ThatOneCoder435
Scratcher
100+ posts

How do I make a sprite smoothly point towards the mouse (instead of using the snappy point towards mouse block)?

Thanks, your project is very useful! however, I'm trying to make the player rotate smoothly, similar to this: https://scratch.mit.edu/projects/723576660/
ThinkingPlanely
Scratcher
100+ posts

How do I make a sprite smoothly point towards the mouse (instead of using the snappy point towards mouse block)?

This should work:

Last edited by ThinkingPlanely (Sept. 11, 2022 18:39:55)

RT_Borg
Scratcher
1000+ posts

How do I make a sprite smoothly point towards the mouse (instead of using the snappy point towards mouse block)?

ThatOneCoder435 wrote:

Thanks, your project is very useful! however, I'm trying to make the player rotate smoothly, similar to this: https://scratch.mit.edu/projects/723576660/

I don't understand what you want to do that my project doesn't. (Maybe something to add?) The values commented in the green flag loop determine how “snappy” the rotation is.

Powered by DjangoBB