private void MoveTowardsPoint(float magnitude, Vector2 point, IPointMovement tileMovement) { var direction = point - currentPosition; var nodeDistance = direction.magnitude; //If we overshot the point if (magnitude > nodeDistance) { currentPosition = point; if (tileMovement != null) { var newPoint = tileMovement.ReachedPoint(); if (newPoint.HasPoint) { MoveTowardsPoint(magnitude - nodeDistance, newPoint.Point, tileMovement); } } } else { MoveWithMagnitude(direction, magnitude); } }
/// <summary> /// Adds a force in direction of CurrentSpeed * speed. /// Callback and lock position to point when reached. /// </summary> public void AddForceTowardsPointWithSpeedMultiplier(Vector2 point, float speed, IPointMovement pointMovement = null) { MoveTowardsPoint(CurrentSpeed * speed * Time.fixedDeltaTime * Time.fixedDeltaTime, point, pointMovement); }
/// <summary> /// Adds a force in direction of CurrentSpeed. /// Callback and lock position to point when reached. /// </summary> public void AddForceTowardsPoint(Vector2 point, IPointMovement pointMovement = null) { MoveTowardsPoint(CurrentSpeed * Time.fixedDeltaTime * Time.fixedDeltaTime, point, pointMovement); }