Hello. I have a small dog that is going back and forth in my scene. I have been able to figure out how to have it pingpong from point A to point B and back to point A, … However, when the dog comes back, it is walking backwards. Does anybody know how I can get the dog to automatically go to one point, turn around and go back to the other, and then continually loop? Any help would be greatly appreciated.
Here is the C# script I am using:
using UnityEngine;
using System.Collections;
public class BackAndForth : MonoBehaviour
{
public Transform farEnd;
private Vector3 frometh;
private Vector3 untoeth;
private float secondsForOneLength = 20f;
void Start()
{
frometh = transform.position;
untoeth = farEnd.position;
}
void Update()
{
transform.position = Vector3.Lerp(frometh, untoeth,
Mathf.SmoothStep(0f,1f,
Mathf.PingPong(Time.time/secondsForOneLength, 1f)));
}
}