Sorry your browser is not supported!

You are using an outdated browser that does not support modern web technologies, in order to use this site please update to a new browser.

Browsers supported include Chrome, FireFox, Safari, Opera, Internet Explorer 10+ or Microsoft Edge.

Dark GDK / Finding an angle in 2d space

Author
Message
EddieV223
14
Years of Service
User Offline
Joined: 24th Sep 2010
Location:
Posted: 1st Oct 2010 07:56
I'm getting ready to program some AI in the game I am making and I need to be able to get the angle that points from one point (the AI's sprite) to another point (the player's sprite) this is math question I am not sure if there is a db function for this or if I'll have to write one myself. If so I'll need some help figuring out the mathematics.


thanks

Learning c++ is a biznatch!
Abraxas77
14
Years of Service
User Offline
Joined: 26th Aug 2010
Location:
Posted: 1st Oct 2010 16:04
If you have two points A and B, the following will give the angle between line AB and the x-axis (horizontal axis):

angle = atanf(xB-xA, yB - yA);

This angle will be in radians; to convert it into degrees:

angleDegrees = 180.0f / PI;


http://en.wikipedia.org/wiki/Angle
Diggsey
18
Years of Service
User Offline
Joined: 24th Apr 2006
Location: On this web page.
Posted: 1st Oct 2010 17:10
atan2f not atanf

[b]
Dodga
14
Years of Service
User Offline
Joined: 12th Dec 2009
Location:
Posted: 1st Oct 2010 22:04
Doing 2.5d is much easier IMO, you can still use images but you use planes in 3d to make those images, its easier because you can just go
dbPointObject(1, x, y, z);
angle=dbObjectAngleY(1);
Neuro Fuzzy
17
Years of Service
User Offline
Joined: 11th Jun 2007
Location:
Posted: 5th Oct 2010 10:41
I love layered topology - you can have 1 flat layer for the ground, and a second slanted layer for stairs connecting the first layer to a third layer above the first. Any object moving taking one layer into account, you really only need to worry about the 2d top-down case.


Still, 3d rotation is pretty cool, just a pain in the butt.

Login to post a reply

Server time is: 2024-11-19 18:37:52
Your offset time is: 2024-11-19 18:37:52