I want to move a cube from Point A to Point B then from Point B to point A this object movement from point A to Point B then from point B to A this movement cycle should repeat thought the game.cube should move from one point to another and should return back to original potion this cube movement should repeat again and again
1.Calculate scalar distance between point A to point B
var moveDirection: Vector3 = (B - A).normalized;
var distance: float = (B - A).magnitude;
-
use Mathf.PingPong(…) interpolate this distance over time
var pingpongDistance: float = distance * Mathf.PingPong(Time.time, 1);
-
calculate position of object
gameObject.transform.position = A + moveDirection * pingpongDistance;