public void Follow(Ch6Fig4FlowField flow) { // What is the vector at the place we're standing in? Vector2 desiredVelocity = flow.Lookup(location); desiredVelocity *= maxSpeed; Vector2 steerVelocity = desiredVelocity - velocity; // Steering is desired minus velocity Vector2.ClampMagnitude(steerVelocity, maxForce); applyForce(steerVelocity); }
// Start is called before the first frame update void Start() { // Instantiate our vehicle, location doesn't matter as it will get overwritten // Instantiate makes a copy of our cone GameObject vehicleObject = Instantiate(vehicleRepresentation, Vector3.zero, Quaternion.identity); vehicle = new Ch6Fig4Vehicle(vehicleObject); // Makes a grid of random vectors that moves our vehicle around field = new Ch6Fig4FlowField(); }