Hey I’m a noob here and I need help making my object follow a path. I’ve used waypoints and the nav bake function but none of them are working. I’v looked all around so and link you’ll send me I would’ve probably already look through.
The problem with this script is that the thing that I want to follow the path doesn’e even move. In fact, nothing at all happens and I have no idea why.
This is my code if you were wondering:
using UnityEngine;
using System.Collections;
public class WayPoints : MonoBehaviour {
public Transform[] wayPoint = new Transform[9];
int currentWayPoint = 1;
public float rotationSpeed = 6.0f;
public float acceleration = 1.8f;
// Use this for initialization
void Start () {
wayPoint [0] = GameObject.Find ("WayPoint1").transform;
wayPoint [1] = GameObject.Find ("WayPoint2").transform;
wayPoint [2] = GameObject.Find ("WayPoint3").transform;
wayPoint [3] = GameObject.Find ("WayPoint4").transform;
wayPoint [4] = GameObject.Find ("WayPoint5").transform;
wayPoint [5] = GameObject.Find ("WayPoint6").transform;
wayPoint [6] = GameObject.Find ("WayPoint7").transform;
wayPoint [7] = GameObject.Find ("WayPoint8").transform;
wayPoint [8] = GameObject.Find ("WayPoint9").transform;
}
// Update is called once per frame
void Update () {
if (currentWayPoint == 9) {
Destroy (this.gameObject);
Player.lives =- 1;
}
else
{
// walk();
}
}
void walk(){
Quaternion rotation = Quaternion.LookRotation (wayPoint [currentWayPoint].position - transform.position);
transform.rotation = Quaternion.Slerp (transform.rotation, rotation, Time.deltaTime * rotationSpeed);
Vector2 wayPointDirection = wayPoint[currentWayPoint].position - transform.position;
float speedElement = Vector2.Dot(wayPointDirection.normalized, transform.forward);
float speed = acceleration * speedElement;
transform.Translate (0, 0, Time.deltaTime * speed);
}
void onTriggerEnter(Collider collider){
if (collider.tag == "WayPoint") {
currentWayPoint ++ ;
}
}
}
thx for your time!