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

#1 2012-07-22 19:30:55

zammer990
Scratcher
Registered: 2012-01-22
Posts: 500+

Pointing towards a set of co-ordinates

I've got the script for pointing towards a set of co-ordinates. But something strange is happening:

when gf clicked
set [delta x v] to ((item [1 v] of [xlocations v]) - (x position))
set [delta y v] to ((item [1 v] of [ylocations v]) - (y position))
if <(delta y) = (0)>
if <(delta x) = (0)>
set [ideal direction v] to (-90)
else
set [ideal direction v] to (90)
end
else
if <(delta y) < (0)>
set [ideal direction v] to (180 + ([atan v] of ((delta x) / (delta y))))
else
set [ideal direction v] to ([atan v] of ((delta x) / (delta y)))
end
I have a turning script after that.
When the target location is -100 -100 the ideal direction is 225, an unreachable target so it just keeps rotating


http://i45.tinypic.com/2ynq7nn.jpg Play now!

Offline

 

#2 2012-07-22 19:36:22

Wes64
Scratcher
Registered: 2011-08-19
Posts: 1000+

Re: Pointing towards a set of co-ordinates

I see no reason why it would keep rotating, there must be some other script causing interference. This script seems like it works properly.


Experienced 2.0 Tester: Ask me questions!
Using Firefox 13.0, Flash plugin version 11.4.402.287, and Windows XP Professional.

Offline

 

#3 2012-07-22 19:38:02

AtomicBawm3
Scratcher
Registered: 2009-06-27
Posts: 1000+

Re: Pointing towards a set of co-ordinates

You should switch the top value to (atan(x/y) - 180) so that it matches up with Scratch's system of degrees, which goes from -180 to 180 instead of from 0 to  360.


http://i50.tinypic.com/j0yw0p.jpg

Offline

 

#4 2012-07-22 19:39:38

zammer990
Scratcher
Registered: 2012-01-22
Posts: 500+

Re: Pointing towards a set of co-ordinates

Wes64 wrote:

I see no reason why it would keep rotating, there must be some other script causing interference. This script seems like it works properly.

Don'[t worry, I fixed it

Last edited by zammer990 (2012-07-22 19:41:51)


http://i45.tinypic.com/2ynq7nn.jpg Play now!

Offline

 

#5 2012-07-22 19:40:55

Ratty1967UK
Scratcher
Registered: 2007-05-16
Posts: 88

Re: Pointing towards a set of co-ordinates

why not create another sprite with a single pixel costume - hide it - make your other sprite point towards it in a forever loop - now simply move the hidden sprite to the desired co-ordinates and the visible sprite will follow the hidden one without all the maths?

Offline

 

#6 2012-07-22 20:21:27

cheddargirl
Scratch Team
Registered: 2008-09-15
Posts: 1000+

Re: Pointing towards a set of co-ordinates

Closed by request.


http://i.imgur.com/8QRYx.png
Everything is better when you add a little cheddar, because when you have cheese your life is at ease  smile

Offline

 

Board footer