Hello i have a script that makes my player move and change paths but how can i have him be effected by gravity and still stay on the path?
here is my code:
using UnityEngine;
using System.Collections;
public class follow : MonoBehaviour {
private float smoothing = 1.0f;
private Vector3 targetPosition;
public float runSpeed = 0;
public Transform[] path0;
public Transform[] path1;
public Transform[] path2;
private Transform[][] paths = new Transform[3][];
private int iPath = 0;
float percentsPerSecond = 0.02f; // %2 of the path moved per second
float currentPathPercent = 0.0f; //min 0, max 1
void Start () {
paths[0] = path0;
paths[1] = path1;
paths[2] = path2;
}
void Update () {
if (Input.GetKeyDown("a")) {
if (iPath == 2) iPath = 1; else iPath = 0;
}
else if (Input.GetKeyDown("d")) {
if (iPath == 0) iPath = 1; else iPath = 2;
}
currentPathPercent += percentsPerSecond * Time.deltaTime;
iTween.PutOnPath(gameObject, paths[iPath], currentPathPercent);
transform.LookAt(iTween.PointOnPath(paths[iPath],currentPathPercent+.05f));
}
void OnDrawGizmos(){
iTween.DrawPath(path0);
iTween.DrawPath(path1);
iTween.DrawPath(path2);
}
}