private IEnumerator MoveToPoint(TilePath tilePath) { OnStartMove.Trigger(); foreach (var node in tilePath) { //var lastDist = Vector3.Distance(Position.SetY(0), node.WorldPosition); float time = 0; OnMoveToBlock.Trigger(node); while (true) { time += Time.deltaTime * moveSpeed; Position = Vector3.Lerp(Position, node, time); var dist = Vector3.Distance(Position.SetY(0), node.WorldPosition); if (dist <= distanceToNode.Value) { GridPosition = node; Position = node.WorldPosition.SetY(Position); break; } yield return(null); } } OnStopMove.Trigger(); MovePlayerCallback.Trigger(); movingCoroutine = null; }
public virtual void PhysicsLateUpdate(float dt) { OnPhysicsLateUpdate(); if (!Math.EqualsEstimate(ForceDuration, 0f)) { ForceDuration = Math.Approach(ForceDuration, 0f, dt); if (Math.EqualsEstimate(ForceDuration, 0f)) { ForcePerSec = Vector2.Zero; JustReceiveForce = IsReceivingForce = false; ForceEnds(); OnForceEnds?.Invoke(); } } Vector2 posDiff = Body.Position - Body.LastPosition; if (posDiff.LengthSquared() > 0f) { if (!IsMoving) { OnStartMove?.Invoke(); } IsMoving = true; OnMoving(posDiff); } else if (IsMoving) { IsMoving = false; OnStopMove?.Invoke(); } }
public void StopMove() { if (IsMoving) { if (MyMovementGroup.IsNotNull()) { MyMovementGroup.Remove(this); } IsMoving = false; StoppedTime = 0; IsCasting = false; if (OnStopMove.IsNotNull()) { OnStopMove(); } } }
public void StopMove() { if (IsMoving) { forcePathfind = false; if (MyMovementGroup.IsNotNull()) { MyMovementGroup.Remove(this); } IsMoving = false; stopTime = 0; IsCasting = false; stuckTick = 0; if (OnStopMove.IsNotNull()) { OnStopMove(); } } }