Mar 23, 2024 17:41:57
How do i make a smooth point at mouse pointer?
view on scratch
view on legacy ocular
SpyCoderX
loading
Well, there is this method to turn at a fixed rate: Hi! Small creators like me feel free to use this to help. But thats not the reason i created this.
How do i create smooth pointing at the mouse pointer?
Heres the code that doesnt work.when green flag clickedforever
point towards [Mouse pointer v]
Credit: RokCoderdefine Turn towards mouse
set [current direction v] to (direction)
point towards [mouse v]
set [target direction v] to (direction)
set [delta direction v] to (((((target direction) - (current direction)) + (180)) mod (360)) - (180))
if <([abs v] of (delta direction)) < (rotation speed*)> then // *rotation speed is the speed at which you want to turn towards the mouse pointer
point in direction (target direction)
else
point in direction ((current direction) + (((delta direction) / ([abs v] of (delta direction))) * (rotation speed*)))
end
You can also use this to turn a certain % at a time:
define Turn towards mouse
set [current direction v] to (direction)
point towards [mouse v]
set [target direction v] to (direction)
set [delta direction v] to ((((((target direction) - (current direction)) + (180)) mod (360)) - (180)) + (current direction))
point in direction (((current direction) * ((1)-(rotation percent*))) + ((delta direction) * (rotation percent*))) //Rotation percent* is a value between 0 and 1