Vehicle
Class
The vehicle class makes it easy to apply steering behaviors
to game characters. Don’t let the name fool you, this class could be used to move
walking characters, space ships, and most things in between.
class
Vehicle { public: Vehicle(); void Step(); void SetSteeringForce(Vector2D desiredVec, Vector2D
lookVec); void Collide(Vehicle &other); Vector2D
position; //Current
position Vector2D
velocity; //Current
velocity Vector2D
lookVec; //Used
internally to rotate the vehicle over time Vector2D
forceVec; //Used
internally, acceleration vector float friction; //Resistance
to movement float wanderDir; //A stored
value needed for the wander behavior float direction; //Current
direction in degrees float maxAcceleration; //Pixels
per second^2 float maxVelocity; //Pixels per
second float maxRotation; //Degrees per
second float radius; //For
collision detection static Core* G; //Set this
pointer before using }; |
The
vehicle accelerates and moves realistically although the concept of mass and
torque have been left out to make the class simple. The “Collide” function only
prevents intersection based on the radius of the colliding objects,
it does not alter their velocity.
Vehicle.zip 2kb