public override void Simulate() { if (IsMoving) { MovementDirection = Destination - Body.Position; long distance; MovementDirection.Normalize(out distance); if (distance > closingDistance) { Body.Velocity += (MovementDirection * timescaledSpeed - Body.Velocity) * SteeringWeight; } else { Body.Velocity += (MovementDirection * ((timescaledSpeed * distance) / (closingDistance)) - Body.Velocity) * SteeringWeight; if (distance < ((closingDistance * closingDistanceMultiplier) >> FixedMath.SHIFT_AMOUNT)) { StopMove(); } } Body.VelocityChanged = true; } else { if (TouchingObjects.Count > 0) { Body.Velocity /= TouchingObjects.Count; } Body.Velocity -= Body.Velocity * SteeringWeight; StopTime++; } TouchingObjects.FastClear(); }
public override void Simulate() { if (IsMoving) { if (RepathCount <= 0) { if (ViableDestination) { if (Pathfinder.GetPathNode(Body.Position.x, Body.Position.y, out CurrentNode)) { if (StraightPath) { if (Pathfinder.NeedsPath(CurrentNode, DestinationNode)) { if (Pathfinder.FindPath(Destination, CurrentNode, DestinationNode, MyPath)) { HasPath = true; PathIndex = 0; } else { if (IsFormationMoving) { StartMove(MyMovementGroup.Destination); IsFormationMoving = false; } } StraightPath = false; RepathCount = RepathRate; } else { RepathCount = StraightRepathRate; } } else { if (Pathfinder.NeedsPath(CurrentNode, DestinationNode)) { if (Pathfinder.FindPath(Destination, CurrentNode, DestinationNode, MyPath)) { HasPath = true; PathIndex = 0; } else { if (IsFormationMoving) { StartMove(MyMovementGroup.Destination); IsFormationMoving = false; } else { } } RepathCount = RepathRate; } else { if (StraightPath == false) { if (IsFormationMoving) { StartMove(MyMovementGroup.Destination); IsFormationMoving = false; } } StraightPath = true; RepathCount = StraightRepathRate; } } } else { } } else { HasPath = false; if (IsFormationMoving) { StartMove(MyMovementGroup.Destination); IsFormationMoving = false; } } } else { if (HasPath) { RepathCount--; } else { RepathCount--; } } if (StraightPath) { TargetPos = Destination; } else if (HasPath) { if (PathIndex >= MyPath.Count) { PathIndex = MyPath.Count; } TargetPos = MyPath [PathIndex]; } else { TargetPos = Destination; } MovementDirection = TargetPos - Body.Position; MovementDirection.Normalize(out distance); if (TargetPos.x != LastTargetPos.x || TargetPos.y != LastTargetPos.y) { LastTargetPos = TargetPos; TargetDirection = MovementDirection; } if (PathIndex + 1 >= MyPath.Count) { if (distance > closingDistance) { Body.Velocity += (MovementDirection * timescaledSpeed - Body.Velocity) * SteeringWeight; } else { Body.Velocity += (MovementDirection * ((timescaledSpeed * distance) / (closingDistance)) - Body.Velocity) * SteeringWeight; if (distance < ((closingDistance * closingDistanceMultiplier) >> FixedMath.SHIFT_AMOUNT)) { StopMove(); } } } else { Body.Velocity += (MovementDirection * timescaledSpeed - Body.Velocity) * SteeringWeight; if (distance <= closingDistance) { PathIndex++; } } Body.VelocityChanged = true; } else { if (Body.VelocityMagnitude > 0) { Body.Velocity -= Body.Velocity * SteeringWeight; Body.VelocityChanged = true; } StopTime++; } TouchingObjects.FastClear(); }