- Home /
Question by
VinDev-InDev · 4 days ago ·
movementrigidbodynpc
How do I make a 3D Rigidbody move along a path indefinitely?
Is there a way to where I can make a script with an array of Transforms that will have the rigidbody move towards them in order?
EG: Point A -> Point B -> Point C -> Point A ...
Comment
Answer by ZY_bros · 4 days ago
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using UnityEngine.AI;
public class Test : MonoBehaviour
{
public Transform[] Destinations;
public NavMeshAgent agent;
void FixedUpdate()
{
for (int i = 0; i < Destinations.Length;)
{
agent.SetDestination(Destinations[i].position);
if(agent.transform.position.x == Destinations[i].position.x)i++;
}
}
use NavMeshAgent Instead
Your answer
Follow this Question
Related Questions
Npc Movement 0 Answers
Movement with NavMeshAgent pushes RigidBody 1 Answer
Character running at super speed 1 Answer
Restrict a Players Movement Up a Slope 1 Answer
[Solved]Why doesn't this Rigidbody.AddForce work the way I tell it to? 1 Answer