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

#1 2009-05-14 18:51:25

keroro645
Scratcher
Registered: 2008-06-07
Posts: 1000+

Sorry but, the direction formula?

How do you make it so that you can point towards a certain coordinate?

Offline

 

#2 2009-05-14 19:26:10

archmage
Scratcher
Registered: 2007-05-18
Posts: 1000+

Re: Sorry but, the direction formula?

The formula would be this normally

    var __x = _xmouse - this._x ;
    var __y = _ymouse - this._y ;
    var angle = Math.atan2(__y, __x)
 

But this is not possible in scratch because of the lack of the atan2 function.

There is probably a way but I am not a math expert and am not sure how to replace the atan2.

If I were you I would just use the point to block.

Last edited by archmage (2009-05-14 19:26:32)


Hi, I am Archmage coder extraordinaire. I do Scratch,pascal,java,php,html, AS2 and AS3. Leave me a message if you want coding advice. Also check out my personal website, lots of good stuff about web development, Flash, and Scratch (v1 and v2) !

Offline

 

#3 2009-05-14 19:37:24

keroro645
Scratcher
Registered: 2008-06-07
Posts: 1000+

Re: Sorry but, the direction formula?

I was gonna use variables taht determined x and y coordinates so i can use that function,

Last edited by keroro645 (2009-05-14 19:37:45)

Offline

 

#4 2009-05-14 19:45:37

archmage
Scratcher
Registered: 2007-05-18
Posts: 1000+

Re: Sorry but, the direction formula?

No you can't use what I posted. Scratch doesn't have a atan2 function.


Hi, I am Archmage coder extraordinaire. I do Scratch,pascal,java,php,html, AS2 and AS3. Leave me a message if you want coding advice. Also check out my personal website, lots of good stuff about web development, Flash, and Scratch (v1 and v2) !

Offline

 

#5 2009-05-14 19:46:25

keroro645
Scratcher
Registered: 2008-06-07
Posts: 1000+

Re: Sorry but, the direction formula?

What is the difference between atan and atan2?

Offline

 

#6 2009-05-14 19:50:31

BoltBait
Scratcher
Registered: 2009-03-09
Posts: 1000+

Re: Sorry but, the direction formula?

keroro645 wrote:

How do you make it so that you can point towards a certain coordinate?

Like this:

http://i57.photobucket.com/albums/g228/BoltBait/PointAway.gif

(only, you'll have to modify this a bit.  It is designed to point away from a sprite)

Where it says "X position of sprite2" use your X coordinate, etc.

Last edited by BoltBait (2009-05-14 19:51:45)


Animated sigs must be banned!
http://boltbait.com/j.pnghttp://boltbait.com/s.pnghttp://boltbait.com/d.pnghttp://boltbait.com/a.pnghttp://boltbait.com/p.png

Offline

 

#7 2009-05-14 19:52:39

archmage
Scratcher
Registered: 2007-05-18
Posts: 1000+

Re: Sorry but, the direction formula?

atan2 considers quadrants whereas atan does not.

If that doesn't make sense then let me put it this way, with atan you can get angles 0 to 90 with atan2 you can get every angle which is what you need.


Hi, I am Archmage coder extraordinaire. I do Scratch,pascal,java,php,html, AS2 and AS3. Leave me a message if you want coding advice. Also check out my personal website, lots of good stuff about web development, Flash, and Scratch (v1 and v2) !

Offline

 

#8 2009-05-15 07:03:24

bosox397
Scratcher
Registered: 2008-02-17
Posts: 1000+

Re: Sorry but, the direction formula?

have a invisible sprite that the guy can point to


Dear Scratch Users,
I'm done with scratch, or at least making projects. I have made one last big game, thats both fun and teaches a lesson about water. It'd mean a lot if you gave me feedback.                              http://scratch.mit.edu/projects/bosox397/569201

Offline

 

#9 2010-03-31 14:47:37

frogger3140
Scratcher
Registered: 2008-12-15
Posts: 500+

Re: Sorry but, the direction formula?

archmage wrote:

atan2 considers quadrants whereas atan does not.

If that doesn't make sense then let me put it this way, with atan you can get angles 0 to 90 with atan2 you can get every angle which is what you need.

atan * 4 = atan2?

Last edited by frogger3140 (2010-03-31 14:48:26)


http://j.mp/piBfFy
Woo, even better minecraft clone! | I feel that programming is better than animation, because you can interact with games but not animations.

Offline

 

#10 2010-03-31 14:50:54

BWOG
Scratcher
Registered: 2008-09-19
Posts: 1000+

Re: Sorry but, the direction formula?

frogger3140 wrote:

archmage wrote:

atan2 considers quadrants whereas atan does not.

If that doesn't make sense then let me put it this way, with atan you can get angles 0 to 90 with atan2 you can get every angle which is what you need.

atan * 4 = atan2?

DON'T. BUMP. OLD. THREADS.

It's been happening too much lately.

Offline

 

#11 2010-03-31 15:04:58

demosthenes
Retired Community Moderator
Registered: 2008-02-19
Posts: 1000+

Re: Sorry but, the direction formula?

I realize this is an old thread, but for those of you wondering how to do it, use this:

http://img718.imageshack.us/img718/5104/screenshot20100331at305.png

Edit:

Wait nevermind.

There is a way better way to do it.

Uploading image now .  . .


Edit2:

There far sleeker way uploaded.

Last edited by demosthenes (2010-03-31 15:07:34)


I've taken a long hiatus, but I still visit sometimes. Give me some time to answer any messages you post on my projects!

Offline

 

Board footer