
[ad_1]
Game Development Stack Exchange is a query and reply website for skilled and unbiased sport builders. It solely takes a minute to enroll.
Anybody can ask a query
Anybody can reply
The finest solutions are voted up and rise to the highest
Asked
Viewed
1k instances
I would like my enemy to maneuver randomly to sure factors on the scene. It strikes to at least one level after which stops! It doesn’t proceed to the opposite factors!
Here is my script:
utilizing UnityEngine;
utilizing System.Collections;
public class emove: MonoBehaviour {
NavMeshAgent ePath;
public GameObject[] POINT;
void Start () {
ePath = GetComponent<NavMeshAgent>();
}
void Update () {
foreach (GameObject waypoint in POINT) {
ePath.SetDestination(waypoint.remodel.place);
ePath.pace = 2;
// I write this, if in case you have totally different thought inform me please
if (waypoint.activeSelf == false) // waypoint had it personal script, when enemy contact any level it set off
{
ePath.SetDestination(waypoint.remodel.place); // transfer to every other energetic waypoint.
ePath.pace = 2;
}
}
}
What am I doing flawed?
$endgroup$
1
The downside lies in your Update(). You are setting a brand new waypoint on your NavMeshAgent each body, throwing in each level with out evaluating in case your NavMeshAgent has reached the earlier waypoint.
utilizing UnityEngine;
utilizing System.Collections;
public class emove: MonoBehaviour {
NavMeshAgent ePath;
public GameObject[] waypoints;
int currentPointIndex;
void Start () {
ePath = GetComponent<NavMeshAgent>();
currentPointIndex = Random.Range(0, waypoints.Length - 1);
//Start navigating to first *random* waypoint
ePath = SetDestination(waypoints[currentPointIndex].remodel.place);
ePath.pace = 2;
}
void Update () {
//reaching present waypoint
if (Vector3.Distance(waypoints[currentPointIndex].remodel.place,
remodel.place < 1)
{
//Find subsequent random waypoint
currentPointIndex = Random.Range(0, waypoints.Length - 1);
//Navigate to subsequent waypoint
ePath.SetDestination(waypoints[currentPointIndex].remodel.place);
}
}
$endgroup$
You should log in to reply this query.
Not the reply you are in search of? Browse different questions tagged .
lang-cs
[ad_2]