The Daily Click ::. Forums ::. Klik Coding Help ::. Angle between two objects?
 

Post Reply  Post Oekaki 
 

Posted By Message

renneF



Registered
  02/08/2003
Points
  672
15th March, 2007 at 05:27:01 -

In MMF2 DEMO
Yes, I have searched the forums/articles. What's the right formula for this?
I currently have:

ATan((Y( "player" )-Y( "mouse" ))/(X( "player" )-X( "mouse" )))
But it doesn't work properly

Thanks

Image Edited by the Author.

 
Image

Joe.H

Evil Faker

Registered
  19/08/2002
Points
  3305
15th March, 2007 at 11:19:58 -

It returns the angle in radians.
pi radians = 180 degrees.
therefore to go from radians to degrees, multiply by 180/pi (or 3.14159)


 
My signature is never too big!!!

renneF



Registered
  02/08/2003
Points
  672
15th March, 2007 at 23:56:10 -

I just want the angle between the player and the mouse!
So it' now:
ATan((Y( "player" )-Y( "mouse" ))/(X( "player" )-X( "mouse" )))*180/3.14159
It Still doesn't work.
I can upload the file if anyone cares to take a look.

Image Edited by the Author.

 
Image

Peblo

Custom ratings must be 50 characters or less

Registered
  05/07/2002
Points
  185

Game of the Week WinnerVIP MemberI'm on a Boat360 OwnerAttention GetterThe Cake is a LieCardboard BoxHero of TimePS3 OwnerIt's-a me, Mario!
I'm a Storm TrooperSonic SpeedStrawberryI like Aliens!Wii OwnerMushroomGhostbuster!
16th March, 2007 at 02:57:12 -

Check your parentheses.

 
"Isn't it always amazing how we characterize a person's intelligence by how closely their thinking matches ours?"
~Belgarath

renneF



Registered
  02/08/2003
Points
  672
16th March, 2007 at 03:18:16 -

The parentheses are okay.
It's a valid expression, but the number it spits out is wrong.

 
Image

Peblo

Custom ratings must be 50 characters or less

Registered
  05/07/2002
Points
  185

Game of the Week WinnerVIP MemberI'm on a Boat360 OwnerAttention GetterThe Cake is a LieCardboard BoxHero of TimePS3 OwnerIt's-a me, Mario!
I'm a Storm TrooperSonic SpeedStrawberryI like Aliens!Wii OwnerMushroomGhostbuster!
16th March, 2007 at 03:36:23 -

ATan( ( Y( "player" ) * 1.0 - Y( "mouse" ) * 1.0 ) / ( X( "player" ) * 1.0 - X( "mouse" ) * 1.0 ) ) * 180.0 / 3.14159
that works in mmf1.5

Image Edited by the Author.

 
"Isn't it always amazing how we characterize a person's intelligence by how closely their thinking matches ours?"
~Belgarath

renneF



Registered
  02/08/2003
Points
  672
16th March, 2007 at 14:38:15 -

Thanks for the help so far
Using what you just said Peblo, minus the *180/3.14159 bit works for 180 degrees but the other (left side) arc doesn't work :/
Times it by two I and get full 360 degrees but at twice the rate it should be going.

http://homepages.ihug.co.nz/~jet2/fenner/kikoshoot.mfa


Image Edited by the Author.

 
Image

renneF



Registered
  02/08/2003
Points
  672
17th March, 2007 at 05:02:53 -

Check it, yo.

 
Image

renneF



Registered
  02/08/2003
Points
  672
18th March, 2007 at 05:51:54 -

Last bump...

 
Image

Joe.H

Evil Faker

Registered
  19/08/2002
Points
  3305
18th March, 2007 at 06:25:11 -

Don't have mmf2.
But, if you want to find all possible angles, you simply subtract or add 180° to the retrieved value.

Only do this between values of -360 and 360.
For negative angles, just do 360-magnitude of angle retrieved (for example, if you have -30 degrees, subtract 30 from 360 and you will get 330 degrees, i.e that is to say the same angle can be retrieved by travelling 360 anti clockwise from the point of calculation)

 
My signature is never too big!!!
   

Post Reply



 



Advertisement

Worth A Click