HELP

Hi i’ve been trying to make games for a while i finally got drawing to screen done, then another prob. crops up.
How do i get the direction from one point to another ie Bearing in degrees?

Edit: i’m a noob Java game creator btw

Math.atan2

:o how would i use that, just pass say, x velocity and y velocity. would it return in degrees?

Basically, an understand of basic geometry mathematics :slight_smile:

  • especially Pythagoras.

Something I learned in school at the age of 15-17 iirc.

Check this site out for help:
http://www.mathopenref.com/coorddist.html

oh i know basic sin cos and stuff and pythagoras

Remember that 1 guy in class whining that this stuff would never be used in real life… He was wrong:D

Very true…

Haha, I was that guy! :slight_smile:

Mike

I probably should mention that all the Math.* methods work in radians, not degrees. Remember if you want to convert between then 2Pi radians = 360 degrees.

There is methods in there to convert between radians and degrees if you’re more relaxed with one.

As all functions in Java are using radians, it doesn’t make sense to store them in degrees as you’ll have to convert them back and forth. Things get trickier if you use OpenGL though as it uses degrees… xD

I guess that while you’re not optimising your code, you can do it, becase it’s easier to debug.

Because System.out.println(Math.toDegrees(degrees)); is harder to write and more error prone compared to using it every time you set the value, plus toRadians() when you use it. >_>

Don’t you mean Math.toDegrees(radians)? :wink:

Hey, man. I name my variables whatever I want! :persecutioncomplex:

You are entirely correct there… ._.