public override bool Update(Unit unit, int deltaTime) { if (unit.HasAnyState(UnitControlState.Root | UnitControlState.Stunned | UnitControlState.Distracted)) { unit.SetMovementFlag(MovementFlags.MaskMoving, false); return(false); } currentCurveTime += deltaTime * curveSpeed / 1000.0f; if (currentCurveTime >= 1.0f) { unit.Position = bezierCurvePoints[3]; return(false); } Vector3 p0 = bezierCurvePoints[0]; Vector3 p1 = bezierCurvePoints[1]; Vector3 p2 = bezierCurvePoints[2]; Vector3 p3 = bezierCurvePoints[3]; float t = currentCurveTime; Vector3 bezierCurvePoint = Mathf.Pow(1 - t, 3) * p0 + Mathf.Pow(t, 3) * p3 + 3 * Mathf.Pow(1 - t, 2) * t * p1 + 3 * (1 - t) * Mathf.Pow(t, 2) * p2; unit.Position = bezierCurvePoint; return(true); }
public override bool Update(Unit unit, int deltaTime) { if (!startedMovement) { startedMovement = true; if (unit is Creature) { return(unit.AI.SetDestination(targetPoint)); } NavMeshPath chargePath = new NavMeshPath(); Vector3 startPosition = unit.Position; if (!NavMesh.SamplePosition(startPosition, out NavMeshHit hit, MovementUtils.MaxChargeSampleRange, MovementUtils.WalkableAreaMask)) { return(false); } startPosition = hit.position; unit.Position = startPosition; if (NavMesh.CalculatePath(startPosition, targetPoint, MovementUtils.WalkableAreaMask, chargePath)) { return(unit.AI.SetPath(chargePath)); } return(false); } if (unit.HasAnyState(UnitControlState.Root | UnitControlState.Stunned | UnitControlState.Distracted)) { unit.AI.NextPosition = unit.Position; unit.SetMovementFlag(MovementFlags.MaskMoving, false); return(false); } if (unit.AI.HasPendingPath) { return(true); } if (!unit.AI.HasPath) { return(false); } unit.Position = unit.AI.NextPosition; unit.SetMovementFlag(MovementFlags.Forward, true); return(unit.AI.RemainingDistance > MovementUtils.PointArrivalRange); }
public override bool Update(Unit unit, int deltaTime) { bool cantMove = unit.HasAnyState(UnitControlState.Root | UnitControlState.Stunned | UnitControlState.Distracted); unit.AI.UpdateRotation = !cantMove; if (cantMove) { unit.AI.NextPosition = unit.Position; unit.SetMovementFlag(MovementFlags.MaskMoving, false); } else if (unit.AI.HasPath) { Vector3 localDirection = unit.transform.TransformDirection(unit.AI.NextPosition - unit.Position); unit.SetMovementFlag(MovementFlags.Forward, localDirection.z > MovementUtils.DirectionalMovementThreshold); unit.SetMovementFlag(MovementFlags.Backward, localDirection.z < -MovementUtils.DirectionalMovementThreshold); unit.SetMovementFlag(MovementFlags.StrafeLeft, localDirection.x < -MovementUtils.DirectionalMovementThreshold); unit.SetMovementFlag(MovementFlags.StrafeRight, localDirection.x > MovementUtils.DirectionalMovementThreshold); unit.Position = unit.AI.NextPosition; } if (cantMove) { return(true); } if (nextMoveTime.Passed) { nextMoveTime.Reset(RandomUtils.Next(1000, 3000)); } else { nextMoveTime.Update(deltaTime); if (nextMoveTime.Passed) { unit.AddState(UnitControlState.ConfusedMove); Vector2 randomCircle = Random.insideUnitCircle * 4; Vector3 randomPosition = unit.Position + new Vector3(randomCircle.x, 0, randomCircle.y); if (!NavMesh.SamplePosition(randomPosition, out NavMeshHit hit, MovementUtils.MaxNavMeshSampleRange, MovementUtils.WalkableAreaMask)) { return(TryAgainSoon()); } randomPosition = hit.position; if (!NavMesh.CalculatePath(unit.Position, randomPosition, MovementUtils.WalkableAreaMask, confusedNavMeshPath)) { return(TryAgainSoon()); } if (!unit.AI.SetPath(confusedNavMeshPath)) { return(TryAgainSoon()); } if (unit.AI.RemainingDistance > MovementUtils.MaxConfusedPath) { return(TryAgainSoon()); } } } return(true); bool TryAgainSoon() { nextMoveTime.Reset(100); return(true); } }