AI Flying Vehicle Rotation Problems
by A F · in Torque 3D Professional · 04/11/2013 (11:18 am) · 8 replies
I am trying to make a new AIFlyingVehicle class.
I'm sending move commands to the Vehicle::ProcessTick function, like the AIPlayer does.
I can get this AIVehicle to more around, but there is something wrong with the way I am calculating its move location.
I started out with similar code to the AIPlayer:
In this video the AIFlyingVehicle (the buggy model closest to the camera) rotates to face the other vehicle. It is only rotating on the Z axis, it is not Pitching here (rotating up and down)
www.youtube.com/watch?v=yziemDJgMT8&feature=youtu.be
This video has the AI trackign a target again. You can see the start of the problem, It rolls as it rotates and doesn't rotate the entire amount it needs to:
www.youtube.com/watch?v=OulMS6j4E98&feature=youtu.be
This video shows it rotating about the correct amount. If it Pitched up it would hit its target:
www.youtube.com/watch?v=27ZFS22XxQI&feature=youtu.be
I originally added similar code to Pitch up and down. I have changed the Pitch code to:
www.youtube.com/watch?v=1S4FButRnTQ&feature=youtu.be
www.youtube.com/watch?v=BqQLJDmiXOk&feature=youtu.be
And here is the effect with both the Yaw and Pitch code:
www.youtube.com/watch?v=_7Sgu-SSp3w&feature=youtu.be
In the video above you can see more Pitch is needed to align with its target.
It is very close to working here:
www.youtube.com/watch?v=l4RT4lPArcM&feature=youtu.be
This video show the target moving straight up and the AI tracking off to the left, then correcting itself to be closer:
www.youtube.com/watch?v=FDj8DCkGnvs&feature=youtu.be
These videos show the real problem. The AI gets close to having the correct movement, then flips out:
www.youtube.com/watch?v=O061Nqt_gQs&feature=youtu.be
www.youtube.com/watch?v=7b9RhQAPjeA&feature=youtu.be
It seems to be working fine if the target is on the same horizontal plane as the AIFlyingVehicle.
Pitching Up or Down seems to throw off the Yaw calculation, and Rolling due to Yawing Left or Right seems to throw off the Pitch calculation.
Antone have any ideas how to fix this?
I'm sending move commands to the Vehicle::ProcessTick function, like the AIPlayer does.
I can get this AIVehicle to more around, but there is something wrong with the way I am calculating its move location.
I started out with similar code to the AIPlayer:
F32 curYaw = rotation.z;
while (curYaw > M_2PI_F)
curYaw -= M_2PI_F;
while (curYaw < -M_2PI_F)
curYaw += M_2PI_F;
F32 newYaw = mAtan2( xDiff, yDiff );
F32 yawDiff = newYaw - curYaw;
if( yawDiff < 0.0f )
yawDiff += M_2PI_F;
else if( yawDiff >= M_2PI_F )
yawDiff -= M_2PI_F;
if( yawDiff > M_PI_F )
yawDiff -= M_2PI_F;
else if( yawDiff < -M_PI_F )
yawDiff += M_2PI_F;
movePtr->yaw = yawDiff * 6;This moves the AIFlyingVehicle around the Z axis to face its target:In this video the AIFlyingVehicle (the buggy model closest to the camera) rotates to face the other vehicle. It is only rotating on the Z axis, it is not Pitching here (rotating up and down)
www.youtube.com/watch?v=yziemDJgMT8&feature=youtu.be
This video has the AI trackign a target again. You can see the start of the problem, It rolls as it rotates and doesn't rotate the entire amount it needs to:
www.youtube.com/watch?v=OulMS6j4E98&feature=youtu.be
This video shows it rotating about the correct amount. If it Pitched up it would hit its target:
www.youtube.com/watch?v=27ZFS22XxQI&feature=youtu.be
I originally added similar code to Pitch up and down. I have changed the Pitch code to:
Point3F pos = getBoxCenter(); Point3F forwardVec; getTransform().getColumn(1, &forwardVec); forwardVec.normalizeSafe(); Point3F targetVec = mAimObject->getBoxCenter(); targetVec -= pos; targetVec.normalizeSafe(); Point3F crossPro; mCross(targetVec, forwardVec, &crossPro); movePtr->pitch = crossPro.x * 6;When only using this code, and not the Yaw code the AIFlyingVehicle Pitches to its target:
www.youtube.com/watch?v=1S4FButRnTQ&feature=youtu.be
www.youtube.com/watch?v=BqQLJDmiXOk&feature=youtu.be
And here is the effect with both the Yaw and Pitch code:
www.youtube.com/watch?v=_7Sgu-SSp3w&feature=youtu.be
In the video above you can see more Pitch is needed to align with its target.
It is very close to working here:
www.youtube.com/watch?v=l4RT4lPArcM&feature=youtu.be
This video show the target moving straight up and the AI tracking off to the left, then correcting itself to be closer:
www.youtube.com/watch?v=FDj8DCkGnvs&feature=youtu.be
These videos show the real problem. The AI gets close to having the correct movement, then flips out:
www.youtube.com/watch?v=O061Nqt_gQs&feature=youtu.be
www.youtube.com/watch?v=7b9RhQAPjeA&feature=youtu.be
It seems to be working fine if the target is on the same horizontal plane as the AIFlyingVehicle.
Pitching Up or Down seems to throw off the Yaw calculation, and Rolling due to Yawing Left or Right seems to throw off the Pitch calculation.
Antone have any ideas how to fix this?
#2
The plane that I am using to calculate the new rotation and movement (and in the above movies I have disabled the forward movement, it only rotates) seems to be the world Plane, not the AIs individual Plane.
Once the AI Rolls it changes the Plane it is on, but my calculations are still using the Original World Plane so the new rotation gets further out from what I want.
04/12/2013 (12:15 am)
Thanks Richard. I'm pretty sure you are right.The plane that I am using to calculate the new rotation and movement (and in the above movies I have disabled the forward movement, it only rotates) seems to be the world Plane, not the AIs individual Plane.
Once the AI Rolls it changes the Plane it is on, but my calculations are still using the Original World Plane so the new rotation gets further out from what I want.
#3
One of the problems I was running into, which made me think it wasn't working in the first place, was the AutoStablizers on the FlyingVehicle.
The amount of radians I was calculating for the AI to turn was fine when the Stablerizers were on, but when it picked up speed the autoStablizers turn off and vehicle can rotate much faster and my AI was always rotating too far then over correcting too far, which made it pitch, roll and yaw away at seemingly random angles.
04/15/2013 (2:07 am)
I got it working. I had to rotate the target location to match the Y rotation of the AI so the current Pitch angle matched the Y angle.One of the problems I was running into, which made me think it wasn't working in the first place, was the AutoStablizers on the FlyingVehicle.
The amount of radians I was calculating for the AI to turn was fine when the Stablerizers were on, but when it picked up speed the autoStablizers turn off and vehicle can rotate much faster and my AI was always rotating too far then over correcting too far, which made it pitch, roll and yaw away at seemingly random angles.
#5
Good catch!
04/15/2013 (7:38 am)
That is an interesting solution - it would probably never have occured to me to rotate the destination. I guess it makes a skewed sort of sense, though.Good catch!
#6
It's code finds how much to the left or right its target is and rotates around the Z axis this amount.
A FlyingVehicle can rotate on its Y axis (rolling), which means its Z axis will also move.
So finding out how much to the left and right in the world its target is doesn't really help to find out how much to rotate around the FlyingVehicles rotated Z axis.
04/15/2013 (5:26 pm)
The normal AIPlayer, like the player, is always orientated with the Z axis matching the world axis.It's code finds how much to the left or right its target is and rotates around the Z axis this amount.
A FlyingVehicle can rotate on its Y axis (rolling), which means its Z axis will also move.
So finding out how much to the left and right in the world its target is doesn't really help to find out how much to rotate around the FlyingVehicles rotated Z axis.
#7
04/15/2013 (5:31 pm)
My approach would probably have been opposite of yours - reset the vehicle's z axis to vertical and then test rather than rotate the target. Not sure if that would work as well (should, but I haven't tried it). I'm just amazed that the engine doesn't have some slick way to get this done, though I guess that also makes sense - the Tribes games had flying vehicles, but the AI didn't use them.
#8
I might try putting that back in again.
[edit]
I originally rotated both the AI and its target so their angle was unchanged but the AI Y axis matched the world axis.
I got better results by only rotating the target.
When I only rotate the AI the location it tries to go to is incorrect.
That doesn't mean thats not the best way, there may be something wrong with the way I am rotating it.
04/15/2013 (6:13 pm)
I did originally rotate the AI back, and that is a bit shorter to do in code, but i discarded that for some reason.I might try putting that back in again.
[edit]
I originally rotated both the AI and its target so their angle was unchanged but the AI Y axis matched the world axis.
I got better results by only rotating the target.
When I only rotate the AI the location it tries to go to is incorrect.
That doesn't mean thats not the best way, there may be something wrong with the way I am rotating it.
Torque Owner Richard Ranft
Roostertail Games