hi all, I'm making a space game where you can have ship fights in 3d space and I'm trying to work out the AI of the enemy ships, specifically the part where they chase the player's ship.
Given an enemy ship at a point in 3d space facing in any possible direction I want to figure out how much he would potentially want to pitch and/or yaw at that point to chase the player ship at another point in 3d space, so I can figure out how much he will pitch/yaw that frame.
Normally if im doing it in 2d I would use atan2 to find a dependable target direction, then a bit of basic math to figure out if the object should turn left or right, but I'm a bit lost at applying that to 3d. I've tried using lookAt constraints to get a bearing to aim for and it kinda works sometimes but is a bit too buggy and erratic.
I found something that says I should use asin for one of the directions but I'm having trouble finding much else about that
make a spaceship follow another in 3d
Started by digijin, Dec 14 2009 06:15 AM
3 replies to this topic
#1
Posted 14 December 2009 - 06:15 AM
#2
Posted 14 December 2009 - 11:13 AM
First of all, in 3D you really should use quaternions for rotations. It'll give you a lot less headaches in the long run, so go study it if you haven't already.
Also read up on how to use "dot product" and "cross product" when working with vectors.
Basically, if you want to turn your spaceship in a certain direction, you would do this:
Then you have the axis you need to turn the spaceship around. You can easily create a quaternion from an axis and an angle.
The exact angle you need to rotate is the Asin (I think) of the length of the axis above. (I'd need to look this up.)
Also read up on how to use "dot product" and "cross product" when working with vectors.
Basically, if you want to turn your spaceship in a certain direction, you would do this:
Axis = Cross(CurrentDirection, WantedDirection);
Then you have the axis you need to turn the spaceship around. You can easily create a quaternion from an axis and an angle.
The exact angle you need to rotate is the Asin (I think) of the length of the axis above. (I'd need to look this up.)
#3
Posted 14 December 2009 - 02:23 PM
just if its more +x if its more +y if its more +z, if its less -, then itll follow but in a strict cube form.
you used to be able to fit a game on a disk, then you used to be able to fit a game on a cd, then you used to be able to fit a game on a dvd, now you can barely fit one on your harddrive.
#4
Posted 23 December 2009 - 08:48 AM
subtract the 2 positions and find the dot product on the normilzed vector
1 user(s) are reading this topic
0 members, 1 guests, 0 anonymous users











