Untitled

mail@pastecode.io avatar
unknown
csharp
a year ago
700 B
4
Indexable
Never
    void runLikeACoward(){
        agent.speed = originalSpeed * 2.5f;
        NavMeshHit hit;
        bool invalidLocation=true;
        int i=0;

        while(invalidLocation){
            Vector3 randomDirection = new Vector3(Random.Range(-10, 10), 0, Random.Range(-10, 10));
            desiredLocation = transform.position + randomDirection.normalized * (10-i*0.1f);
            if(!NavMesh.SamplePosition(desiredLocation, out hit, 5, NavMesh.AllAreas)){ 
                invalidLocation=true;
                i++;
            }
            else invalidLocation=false;
        }        

        if(isCowarding) Invoke(nameof(runLikeACoward), 2);
        else agent.speed = originalSpeed;
    }