Take the 2-minute tour ×
Game Development Stack Exchange is a question and answer site for professional and independent game developers. It's 100% free, no registration required.

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

share|improve this question

1 Answer 1

Provided your aircraft speed is constant, you can "easily" compute a closed form trajectory.. but you have to renounce quaternions and think in terms of spherical coordinates. Since the aircraft velocity vector (when normalized) lies on a sphere, its orientation is thus describable by a parameterization of the sort:

x(t) = sin(t0 + k1 t) sin( f0 + k2 t)

y(t) = cos(t0 + k1 t)

z(t) = sin(t0 + k1 t) cos( f0 + k2 t)

When you know the tangent field of moving particle, mathematically you are assured you can recover the trajectory (see the fundamental curve theorem). you do know this field since the assumed parameterization is the above one. Just substitute k1 and k2 for your HORIZ/VERT_SPEED constants and t0/f0 for an angular offset (what were the two airplane angles when you started your AI trajectory estimator).

You ended up with a parameterization of the velocity vector in terms of time (t). You need to integrate this velocity field from t_start to t_end and get the exact location of your airplane, provided the speed is constant. (You, of course, need to multiply the velocity by that speed scalar to account for higher or lower speeds - this is unit velocity as given above!). Integrating ∫(x(t),y(t),z(t)) dt can be done component wise and for that, if you're lazy like me or forgot much of the calculus tricks, you can use http://integrals.wolfram.com/. Once you get the primitive expressions, use those to find the position (via the fundamental thm of calculus ...)

share|improve this answer
    
Thanks at first for your answer! :) But I'm afraid I can't get it to work. You write, that I could paramterize the velocity as described above and thats what I was hoping, but my tests and my calculations show, that this does not fit the reality. I think the problem is, that the aircraft is rotated around it's own axis, which get rotated in effect, too. If I choose a simple curve parallel too one of the spaces planes, the curve simplifies to a circle and your method works. In all other cases sadly not. :/ Did I miss something about your method? –  Kronos Jul 18 '13 at 15:26
    
Ok I just verified that my curves aren't even closed. –  Kronos Jul 18 '13 at 17:43
    
One remark: an airplane's direction can be given in spherical coordinates, so if you can compute the correct spherical parameterization (x,y,z)(t) for the velocity vector's direction w.r.t. to time, and if you consider the velocity vector to be constant, you should be able to find the displacement (it's only newtonian reasoning). Maybe you could explain a bit how your airplane's velocity model is computed and write the parameterization you're using? That way I could better aid you.. –  teodron Jul 19 '13 at 8:16
    
The parameterization is what I am trying to figure out, it's not existant in the code yet, because the movement gets computed iterative for each frame and step with the code I gave at the top. At each frame the aircraft rotates around in its local space, so every parameterization I could calculate till now is recursive. I will add it too the question. –  Kronos Jul 19 '13 at 9:56
    
If your paramX and paramY aren't constant or trivially dependent on the time parameter, t, then it becomes almost impossible to predict the trajectory analytically. By trivially dependent I imply either a step function (1/0 switching for example) or linear (or anything predictable..). If they come from a physics component or read from a a spline, then it's kind of complicated. Where do you get these params from and what do they mean for your engine? –  teodron Jul 19 '13 at 10:11

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.