Game Development Reference
In-Depth Information
Creating the Tank's Patrol/Attack State
The main tank state is the patrol/attack state, where the tank moves around the playfield according
to waypoints, while firing its weapon at the player's power pyramid. More specifically, the bottom
part of the tank turns toward the current waypoint and moves toward it, while the top part of the tank
turns toward the pyramid and fires at it.
The StateTankSteerWayPoint class implements the patrol/attack state for the tank and is derived
from the StateTank class discussed previously.
public class StateTankSteerWayPoint extends StateTank
The m_WayPoint variable holds the location of the current waypoint that the vehicle is moving toward.
private Vector3 m_WayPoint = new Vector3(0,0,0);
The m_WayPointRadius variable holds the radius of the waypoint. If the tank is within the area
denoted by the current waypoint and the waypoint's radius, the tank is considered to have reached
the waypoint.
private float m_WayPointRadius = 0;
The m_LastWayPoint variable holds the waypoint that was reached previously, just before the current
waypoint.
private Vector3 m_LastWayPoint = new Vector3(5000,5000,5000);
If the tank's turret is pointing at the target plus or minus the m_TargetAngleTolerance value, the tank
will fire at the target.
private float m_TargetAngleTolerance = Physics.PI/16.0f;
The m_Target variable holds the location of the target to fire at, if any.
private Vector3 m_Target;
The m_TargetObj variable holds the target object to fire at, if any.
private Object3d m_TargetObj;
The m_WeaponType variable holds the type of weapon either primary or secondary to fire at the target.
private AIVehicleObjectsAffected m_WeaponType;
The m_RoundsToFire variable holds the number of rounds to fire in one burst.
private float m_RoundsToFire = 0;
 
Search WWH ::




Custom Search