public void MoveTo_TimeToTargetHasPredictedValue() { _mover = instantiateMover() as LinearMover; // Formula: t = s / v (t: Time in seconds | s: distance | v: velocity.magnitude) float predictedTime = _initialDistanceVector.magnitude / _testSpeed; _mover.MoveTo(_target); Assert.AreEqual(_mover.TimeToTarget, predictedTime); }
public IEnumerator MoveTo_MovedBySpeedAfterFixedUpdate() { _mover = instantiateMover() as LinearMover; _mover.MoveTo(_target); yield return(new WaitForFixedUpdate()); float predictedRemainingDistanceToTarget = _initialDistanceVector.magnitude - _testSpeedPerFixedUpdate; float actualRemainingDistaceToTarget = (_target - (Vector2)_mover.transform.position).magnitude; Assert.AreEqual(predictedRemainingDistanceToTarget, actualRemainingDistaceToTarget, _epsilon); }
public IEnumerator MoveTo_ReachesTargetAfterPredictedTime() { Time.timeScale = 20f; _mover = instantiateMover() as LinearMover; _mover.MoveTo(_target); float predictedTime = _mover.TimeToTarget; float timeLeft = predictedTime; while (timeLeft > Time.deltaTime) { Assert.AreNotEqual(_target, (Vector2)_mover.transform.position); timeLeft -= Time.fixedDeltaTime; yield return(new WaitForFixedUpdate()); } yield return(new WaitForFixedUpdate()); Assert.AreEqual(_target, (Vector2)_mover.transform.position); Time.timeScale = 1f; }