Follow a path automatically

Hi, I’m trying to make my ball follow a path automatically. I will explain myself better.

I spawn a path randomly that goes left right and straight, I want the ball follow the path automatically (the player doesn’t have to move the ball)

Have you some ideas? Thank you :slight_smile:

float speed = 50f;
void update(){
    player.position = Vector3.MoveTowrads(player.position, 
    destination.position, speed * Time.deltaTime);
}

Unity has a NavMesh system that can be used in situations just like this. So you could do the following:

  1. Add waypoints to the paths that you are spawning to mark the route for you ball to follow. Create a new Waypoint component and add it to empty GameObjects that you position along the path and connect together to form paths.
  2. Build a NavMesh for your paths.
  3. Make your ball a NavMeshAgent.
  4. Set the destination of the ball to be the position of the first waypoint. When the ball gets close enough to it, set its new destination to be the next waypoint, etc.

Brackeys made a video about NavMesh on youtube.