Game Development Community

Applying thrust in a particular direction

by Jack Stone · in General Discussion · 05/19/2013 (6:14 pm) · 14 replies

Hello,

Yes, this is another rocket science question! I couldn't find a better place to put in than in General Discussion since it's not engine specific and there is not "Math" forum. I am thinking we really should have one?

Anyway, at the moment I have my rocket flying in a straight line, along the Y axis. I have added the ability to rotate the shape using the numpad, this allows for full roll/pitch/yaw control.

The thrust is being applied as follows:
Point3D Fthrust = Point3D(0,thrust,0);

Which, very simply, applies all of the rockets force along the positive Y axis.

What I need some advice on is how to modify this using the rocket's current rotation, to apply the thrust in all directions?

I assume that the thrust is a vector pointing in a particular direction, and I need to combine it with the direction vector of the rocket to apply the correct thrust?

#1
05/19/2013 (9:17 pm)
Your rocket has a matrix transform, right? I'm pretty sure MatrixF has a getForwardVector function which should do that you're looking for.
#2
05/20/2013 (12:43 pm)
The rockets XYZ position is stored in a point3D. The user rotates a static shape in the game, and I am getting the rotation from the transform of that staticshape, which is stored as a matrix.

I can grab the forward vector of the shape like this:
VectorF fv = obj->getTransform().getForwardVector();

However, I am still unsure as to how to apply this to my thrust. I will experiment with it!


#3
05/20/2013 (2:58 pm)
getForwardVector will give you a unit vector (length 1). You can scale this by the amount of thrust before applying it. In effect, you're combining the two things that make a vector a vector: direction (a unit vector) and length (a scalar).
#4
05/20/2013 (4:15 pm)
Yeah, that's what I am doing, and it's still applying the thrust along the same (positive Y) axis.

I am simply doing this:
VectorF Fthrust = obj->getTransform().getForwardVector()*thrust;

Which seems overly simplistic?
#5
05/20/2013 (6:01 pm)
Nope, that makes total sense. First thing to do is step through your program to see where the forward vector is pointing!
#6
05/20/2013 (8:36 pm)
Ok, thats good! At least I know it *should* be working!

I think the issue is that the rotation is not on the correct axes, so when the rocket is pointing towards positive x, the forward vector returns a direction along positive y, for example.

#7
05/21/2013 (7:54 am)
That shouldn't happen. The thrust should be fully applied along the local y axis not the world y axis with the code you've written. Perhaps getForwardVector() doesn't do what we think it does? Maybe it's returning the current direction of movement and thus is simply compounding our motion in our current direction? This should not be the case, but stranger things have happened.

Have you tried echoing the forward vector for comparison?
#8
05/21/2013 (1:09 pm)
I think that may be what is happening Richard.

Just to clarify what seems to be happening: (I may be getting confused with all this vector/matrix/quaternion rotation!)

Applying rotations in script (to eliminate any issues with my rotation code):

$rocket.settransform("0 0 0 1 0 0 0");
Forward Vector is 0 1 0.
Rocket is facing along positive Z axis.

$rocket.settransform("0 0 0 0 1 0 -1.57");
Rocket is now facing along the positive X axis, forward vector is still
0 1 0

There's something definitely wrong with the rotation here, I just can't figure out what it is.
#9
05/21/2013 (5:31 pm)
I think I have figured this out, it was a really simple oversight.
The FORWARD vector is basically the "eye" vector of a human character. If a model is oriented with the top facing up the Z axis, then the forward vector will be facing along the Y axis, in the direction the character will be walking.
However, rockets travel straight up, not sideways, so if the rocket is facing up the Z axis, using the up vector seems to produce the correct vector. I should have noticed that, I just wasn't thinking of the rocket as a "Player", so I didn't think of the obvious difference in how they move.

I'm still having difficulty getting the rocket to move in the right direction, but at least I am getting closer.

Thanks for all of your help!
#10
05/21/2013 (7:54 pm)
Haha, that's tricky! Yes, if you make the rocket face the +x direction, you're rotating it around the y axis, which is the forward axis, so it won't change.

Quote:Forward Vector is 0 1 0.
Rocket is facing along positive Z axis.
There's your hint - the rocket's 'forward' is not the same as the way it is pointing. There isn't, unfortunately, a getUpVector function - that would be helpful in this case!
#11
05/22/2013 (11:16 am)
Actually, I think there is:
VectorF Fthrust = obj->getTransform().getUpVector()*thrust;
Is working fine. Unless I'm missing something?
I could always just rotate the forward vector by 90 degrees.
#12
05/22/2013 (12:41 pm)
Oh wow. Okay, I'd never seen that before. I'm glad to be proven wrong!
#13
05/24/2013 (5:12 pm)
Yeah, there are few other handy vectors in there too. It may have been aded fairly recently, I don't remember seeing them before.
#14
05/25/2013 (8:08 am)
Git blame may reveal more!