This is a read-only archive of the old Scratch 1.x Forums.
Try searching the current Scratch discussion forums.

#1 2011-03-04 09:28:49

theteacher7777
Scratcher
Registered: 2009-11-16
Posts: 1

Problem after towards cursor

Hi all

I have a sprite on the screen, which I want to move towards wherever the cursor is. The code for the sprite I've used is this:

Forever
   Repeat<until touching mouse pointer>
      Point towards mouse pointer
      Move 20
End forever

When I run this, the sprite happily moves towards the cursor. The problem is that when it gets to it, it sort of hovvers around it, moving continually left and right a little bit rather than just stopping. I haven't been able to work out why, or a solution to solve the problem.

Can anyone help please?

Offline

 

#2 2011-03-04 10:05:41

Andres-Vander
Scratcher
Registered: 2010-09-16
Posts: 1000+

Re: Problem after towards cursor

It's in a forever loop, which means it'll keep moving towards the mouse by 20 pixels

However the mouse is only 1 pixel and it might be missing the mouse so it'll keep moving towards it


http://www.gifsoup.com/view1/2260823/flugelhorn-feline-o.gif

Offline

 

#3 2011-03-04 15:54:05

Harakou
Community Moderator
Registered: 2009-10-11
Posts: 1000+

Re: Problem after towards cursor

The sprite is probably jumping past the cursor, so it's never actually touching the mouse. This usually stops being a problem with larger sprites; how big is yours?


http://www.blocks.scratchr.org/API.php?action=random&amp;return=image&amp;link1=http://i.imgur.com/OZn2RD3.png&amp;link2=http://i.imgur.com/duzaGTB.png&amp;link3=http://i.imgur.com/CrDGvvZ.png&amp;link4=http://i.imgur.com/POEpQyZ.png&amp;link5=http://i.imgur.com/ZKJF8ac.png

Offline

 

#4 2011-03-04 16:20:16

shadow_7283
Scratcher
Registered: 2007-11-07
Posts: 1000+

Re: Problem after towards cursor

If you don't want to change the size of the sprite, here is another solution.

forever
   repeat until (distance to [mouse pointer]) < 21
      point towards [mouse pointer]
      move (20) steps
   go to [mouse pointer]
end forever

This will stop the sprite when it is less than 21 steps away from the cursor. Then, wherever it is, it will jump immediately to the mouse pointer.

Offline

 

Board footer