public void Update(double time_elapsed) { this.TimeElapsed = time_elapsed; //calculate the combined force from each steering behavior in the //vehicle's list Vector2 steeringForce = steering.Calculate(); //Acceleration = Force/Mass Vector2 acceleration = steeringForce * (float)(1 / mass); //update velocity velocity += acceleration * (float)time_elapsed; //make sure vehicle does not exceed maximum velocity Helper2.Truncate(ref velocity, maxSpeed); //update the position position += velocity * (float)time_elapsed; //update the heading if the vehicle has a non zero velocity if (velocity.LengthSq() > 0.00000001) { heading = Vector2.Normalize(velocity); side = Helper2.Perp(heading); } //treat the screen as a toroid Helper2.WrapRound(ref position, world.cxClient, world.cyClient); }
public Vehicle(GameWorld world, Vector2 position, float rotation, Vector2 velocity, float mass) { this.world = world; this.position = position; this.heading = new Vector2((float)+Math.Sin(rotation), (float)-Math.Cos(rotation)); this.side = Helper2.Perp(this.heading); steering = new SteeringBehavior(this); this.mass = mass; this.maxSpeed = 150.0f; this.maxForce = 2.0f * SteeringBehavior.steeringForceTweaker; }