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.

DarkBASIC Discussion / 3D angle calculations...

Author
Message
BN2 Productions
21
Years of Service
User Offline
Joined: 22nd Jan 2004
Location:
Posted: 4th Mar 2008 22:41 Edited at: 4th Mar 2008 22:43
This is for a set of AI functions I am writing for an fps. The Computer needs to know at what angle an object is to itself and adjust its course to aim at the object. This is simple if the computer is at 0,0,0, but in this case, it isn't. I found some formulas in an AI programming book for 2D, those are:

x=Xcos(angle)+Ysin(angle)
y=-Xsin(angle)+Ycos(angle)

X is the computer's x coordinate and Y is its y coordinate. Angle is the computer's current heading. x and y are the coordinates of the object the computer is looking for.

I can't just use some simple x,y, and z trig because as the computer turns, offsets in the x direction now have components in other axis as well. Now onto my question, how can these two formulas be adapted for 3D? I realize that in a FPS you really are only working on 2 axis, but this particular function should hopefully be able to be used even on flight simulators.

Let me know if this makes sense.
Thanks in advance
Latch
18
Years of Service
User Offline
Joined: 23rd Jul 2006
Location:
Posted: 5th Mar 2008 00:21 Edited at: 5th Mar 2008 00:29
You can make it a little simpler on yourself by using POINT OBJECT() and collecting the angles. Check out my last entry in the DarkBASIC Challenge thread. The red guy follows the blue using these steps:

1. record reds original angles
2. point red towards blue
3. record reds new angles
4. return red to it's original heading using the old angels
5. use CURVEANGLE() to smoothly interpolate the original angles to the new angles while moving forward.

The order of rotation is important so you may have to experiment a little bit and possibly use SET OBJECT ROTATION ZYX. See if this helps before diving into more meaty trig.

Enjoy your day.

Login to post a reply

Server time is: 2025-06-04 02:09:36
Your offset time is: 2025-06-04 02:09:36