Skip to content

Commit

Permalink
New TickedVehicle.Stop method
Browse files Browse the repository at this point in the history
Previously, when update realized that the vehicle could not move it would
zero its velocity, to avoid having left-over velocity move the vehicle
when it was re-enabled and before the new direction was re-calculated.

I've decided to separate this into an explicit Stop() method, since I
don't really like the idea of having a hidden velocity alteration. Users
may want to move the vehicle somewhere else on their own, while having it
continue at its previous speed when re-enabled.
  • Loading branch information
Ricardo J. Mendez committed Aug 30, 2013
1 parent d6e3028 commit e6eca15
Showing 1 changed file with 6 additions and 10 deletions.
16 changes: 6 additions & 10 deletions Behaviors/TickedVehicle.cs
Original file line number Diff line number Diff line change
Expand Up @@ -292,21 +292,11 @@ protected void AdjustOrientation(float deltaTime)

void Update()
{
// We still update the forces if the vehicle cannot move, as the
// calculations on those steering behaviors might be relevant for
// other methods, but we don't apply it.
//
// If you don't want to have the forces calculated at all, simply
// disable the vehicle.
if (CanMove)
{
ApplySteeringForce(Time.deltaTime);
AdjustOrientation(Time.deltaTime);
}
else
{
ZeroVelocity();
}
}

[System.Diagnostics.Conditional("TRACE_ADJUSTMENTS")]
Expand All @@ -318,6 +308,12 @@ void TraceDisplacement(Vector3 delta, Color color)
}
}

public void Stop()
{
CanMove = false;
ZeroVelocity();
}


}

Expand Down

0 comments on commit e6eca15

Please sign in to comment.