Discuss Scratch

redbrain
Scratcher
18 posts

Mouse-Pointer Controls Glitching

I am making a game where the character is being moved by mouse-pointer.
Here is the script:


forever
if <not <(distance to [ mouse-pointer ]) = [ 0 ]>> then
point towards [ mouse-pointer ]
move (GameSpeed) steps
end
end
(where GameSpeed is a variable describing how many steps the sprite should take :: custom-arg)

When the pointer comes to a stop, the character (which is on side-to-side rotation) catches up and starts rapidly switching from side to side.
Why is this happening, and how can I stop the sprite from flipping (out) ?

-RB

P.S. My browser / operating system: Windows NT 10.0, Chrome 59.0.3071.115, Flash 26.0 (release 0)
footsocktoe
Scratcher
1000+ posts

Mouse-Pointer Controls Glitching

redbrain wrote:

I am making a game where the character is being moved by mouse-pointer.
Here is the script:


forever
if <not <(distance to [ mouse-pointer ]) = [ 0 ]>> then
point towards [ mouse-pointer ]
move (GameSpeed) steps
end
end
(where GameSpeed is a variable describing how many steps the sprite should take :: custom-arg)

When the pointer comes to a stop, the character (which is on side-to-side rotation) catches up and starts rapidly switching from side to side.
Why is this happening, and how can I stop the sprite from flipping (out) ?

-RB

P.S. My browser / operating system: Windows NT 10.0, Chrome 59.0.3071.115, Flash 26.0 (release 0)

Gamespeed steps is some number greater than one. Therefore the sprite never exactly reaches the mouse pointer but always goes a little past it. So then it has to go the other way and then back and then back and that's why you see the flipping. Make gamespeed steps equal to one and the flipping should stop.


SHOOT THE SPACE MONSTERS! ….. A game everyone can play! Bright colors, bonky sounds!
THE 12 BALLS OF CRAZY AL ……. New scrolling adventure game!

Scratch-Minion
Scratcher
1000+ posts

Mouse-Pointer Controls Glitching

When you are within distance GameSpeed of the mouse-pointer go to mouse-pointer.

forever
if <not <(distance to [ mouse-pointer ]) < (GameSpeed)>> then
point towards [ mouse-pointer ]
move (GameSpeed) steps
else
go to [mouse-pointer v]
end
end



AwesomeSmilee
Scratcher
500+ posts

Mouse-Pointer Controls Glitching

forever
point towards [mouse-pointer v]
move ((distance to [mouse-pointer v]) * ((gamespeed) * (0.9))) steps
end
I think this would work better. It eliminates the issue of it flipping, provides a smoother experience and is still controlled by “gamespeed”.

Last edited by AwesomeSmilee (July 24, 2017 09:47:43)

footsocktoe
Scratcher
1000+ posts

Mouse-Pointer Controls Glitching

AwesomeSmilee wrote:

forever
point towards [mouse-pointer v]
move ((distance to [mouse-pointer v]) * ((gamespeed) * (0.9))) steps
end
I think this would work better. It eliminates the issue of it flipping, provides a smoother experience and is still controlled by “gamespeed”.

You might think it would, but I didn't so I created a project that used it. Sorry, but it only works for the special case of gamespeed = 1.

Last edited by footsocktoe (July 24, 2017 13:06:18)



SHOOT THE SPACE MONSTERS! ….. A game everyone can play! Bright colors, bonky sounds!
THE 12 BALLS OF CRAZY AL ……. New scrolling adventure game!

Powered by DjangoBB