public Vector2 Update(Vehicle vehicle, GameTime gameTime) { _currentWanderAngle += RateOfChangeOfDirection * (float) (_random.NextDouble() * 2 - 1); _lastDirectionChangeTime = (int) gameTime.TotalGameTime.TotalSeconds; var circlePosition = Vector2.Normalize(vehicle.Velocity)*CircleDistance +vehicle.Position; var circleOffset = new Vector2((float)(CircleRadius * Math.Cos(_currentWanderAngle)), (float)(CircleRadius * Math.Sin(_currentWanderAngle))); var steeringDirection = (circlePosition+ circleOffset) - vehicle.Position; return steeringDirection; }
public Vector2 Update(Vehicle vehicle, GameTime gameTime) { // Todo: // Add a value of between -RateOfChangeOfDirection and RateOfChangeOfDirection to the _currentWanderAngle variable. // Update the variable every half second, so the changes in steering are more obvious // Hint: // You can use the _random variable that was passed in to the constructor to get a random value between -1 and 1. // Todo: // Figure out the circle position by taking the vehicles velocity (vehicle is a parameter passed into this method), // normalising it, multiplying by the circle distance, and finally adding the vehicles position. // Todo: // Calculate an offset on the steering circle based on the value in the _currentWanderAngle variable and the radius // of the circle, whose value is stored in CircleRadius. // Todo: // Return a steering direction that represents a vector from the vehicles position to the point on the steering cirle // you just calculated. return Vector2.Zero; }
public Entity(Game game, SpriteBatch spriteBatch, Vehicle vehicle) : base(game) { _spriteBatch = spriteBatch; _vehicle = vehicle; }