To start honestly, this question is probably mostly handling math. But thats only the road I tried to go and failed miserably, so maybe theres a much more simple way to do.
Ok the game situation is pretty simple: A 3D space game with nearly no constraints. I don't care about physics in this game, besides from collision.
There is an aircraft (or actually more of them) that gets moved forward every frame according to it's speed and the delta time. The movement of the aircraft occurs according to its own z-Axis. Before the translation the aircraft gets rotated, too. First around it's y-Axis and then around it's x-Axis. The result is a simply controllable aircraft.
Here some code for you:
void Update()
{
//Rotate left/right
float h = HORZ_SPEED * paramX * Time.deltaTime; //HORZ_SPEED is a fixed property of the aircraft, paramX an input value
Quaternion deltaRotation = Quaternion.Euler(Vector3.up*h);,
rigidbody.MoveRotation(rigidbody.rotation * deltaRotation);
//Vertical rotation
float v = VERT_SPEED * (-1.0f) * paramY * Time.deltaTime;
deltaRotation = Quaternion.Euler(v,0,0);
rigidbody.MoveRotation(rigidbody.rotation * deltaRotation);
//Translation
rigidbody.velocity = this.speed * transform.TransformDirection(Vector3.forward);
}
I simplified it a bit, but it's not really much more to that. The problem now is: I want to predict this movement.
For different AI issues like collision avoidance and pattern recognition, I would like to calculate with constant parameters v
and h
and speed
, where my aircraft would be at a point in time X seconds in the future.
What I tried is calculating it the hard way, starting with a start position of object axes, speed and rotation per second and constructing transformations and positions for a few frames progress, hoping it would collapse to a simple pattern. But I didn't find it.
If got the strong feeling that this kind of movement should form a simple pattern like a circle (ok, not soo simple) or an ellipse that I can calculate through a few variables. But I can't seem to make my mind up what that pattern should be and how I can calculate it's characteristics out of the data I have.
EDIT: What I managed to calculate is the transformation the local unit vectors take each frame:
e_z -> e_y * sin(a_y) + [e_z * cos(a_x) + e_x * sin(a_x)]*cos(a_y)
e_x -> e_x * cos(a_x) - e_z * sin(a_x)
e_y -> e_y * cos(a_y) - [e_z * cos(a_x) + e_x * sin(a_x)]*sin(a_y)
On the right all unit vectors are used in their state of the last frame.
a_x and a_y are the rotation parameters for the x resp. y axis:
a_x = VERT_SPEED * paramY
a_y = HORZ_SPEED * paramX