I have a platform that interpolates between two points. The issue is that if the player stands still on the moving tile. If he doesn’t run with it, it will move out from under his feet. It should be as if in real life. If you jump on something spining, you will spin with it, and so on. This object doesn’t spin however, it moves left, right, up, down, and at an angel. Any advice here? This is my current script.
public class XY_MoveScript : MonoBehaviour
{
//Movement Parameters.
public Transform pointA;
public Transform pointB;
public bool startAutomaticly;
public bool startFromTrigger;
public GameObject triggerObject;
public Vector3 offset;
public float speed;
public float delayStartBy = 0;
private bool go;
private Transform destination;
private bool yes;
void Awake() { transform.position = pointA.position; }
void Start()
{
//---------------Through Errors if Needed----------------
if (!startFromTrigger && !startAutomaticly) { Debug.LogError("You have not specified to StartAutomaticly or StartFromTrigger!" + this.gameObject); return; }
if (startAutomaticly && startFromTrigger) { Debug.LogError("You have StartFromTrigger And Start automaticly checked on " + this.gameObject + "!"); return; }
if (startFromTrigger && !triggerObject) { Debug.LogError("You have Start from trigger checked, but you forgot to apply the TriggerGO1 prefab!" + this.gameObject); return; }
//-------------------------------------------------------
destination = pointB;
if (startAutomaticly)
{
StartCoroutine(WaitTime());
}
else if (startFromTrigger)
{
go= false;
GameObject trigger = Instantiate(triggerObject, transform.position + offset, transform.rotation) as GameObject;
}
}
void Update()
{
if (go)
{
float step = speed * Time.deltaTime;
transform.position = Vector3.MoveTowards(transform.position, destination.position, step);
if (transform.position == pointB.position)
{
destination = pointA;
}
else if (transform.position == pointA.position)
{
destination = pointB;
}
}
}
private IEnumerator WaitTime()
{
//Wait this long.
yield return new WaitForSeconds(delayStartBy);
go = true;
}
}