Monday, November 28, 2022
HomeGame Developmentunity - Including constant wandering/patrolling code to my enemy script

unity – Including constant wandering/patrolling code to my enemy script


I’ve been trying all over the place for a patrolling/wandering code/system for my slender-esque recreation. Nevertheless, I’m having bother discovering something and even implementing something and have not been capable of finding solutions wherever (probably as a result of not asking the precise questions on-line).

I did initially discover one script that considerably labored but it surely type of broke on me (it might not change out of the “wandering” state after a couple of edits that I made to it).

My query is what can be the really helpful code to enter?

right here is my code:

utilizing System.Collections;
utilizing System.Collections.Generic;
utilizing UnityEngine;
utilizing UnityEngine.AI;

public class StalkerAI : MonoBehaviour
{

   public playerinventory Playerinventory; //for issue scaling

public NavMeshAgent agent;
public Remodel Participant;

public float stroll; //velocity for enemy to go
public float run;

void Begin()
{
    agent = GetComponent<NavMeshAgent>();

    stroll = 3 + Playerinventory.NumbOfClues;
    run = 5 + Playerinventory.NumbOfClues;
}
// Replace is named as soon as per body
void Replace()
{
    float distValC = 5.0f;
    float dist = Vector3.Distance(agent.remodel.place, Participant.place);

    if (dist <= distValC)
    {
        agent.velocity = run;
        agent.SetDestination(Participant.place);
    }
    else
    {
        agent.velocity = stroll;
        agent.SetDestination(agent.remodel.place);

    }
}

}

RELATED ARTICLES

LEAVE A REPLY

Please enter your comment!
Please enter your name here

- Advertisment -
Google search engine

Most Popular

Recent Comments