help getting an npc to avoid walls

hey guys

im learning in class on how to get characters to ‘see’
lecturer mentioned 2 ways.

raycasting and using ‘feelers’ which are just colliders with detects if its collided with something.

for the collider method, ive set a character with a box collider in front of it and a constant force added to the character. the collider is set to istrigger and has this script attached to it.

using UnityEngine;
using System.Collections;

public class Feeler_GD : MonoBehaviour 
{
    public GameObject player;
    public float turnSpeed;

    void OnTriggerEnter(Collider other)
    {
        player.rigidbody.AddTorque(0, turnSpeed, 0);
    }
    void onTriggerExit(Collider other)
    {
        player.rigidbody.AddTorque(0, -turnSpeed, 0);
    }

}

this code results in it kind of just rotating when it gets to an open space…

using UnityEngine; 
using System.Collections; 

public class Feeler_GD : MonoBehaviour 
{ 
    public GameObject player; 
    public float turnSpeed; 

    void OnTriggerStay(Collider other) 
    { 
        player.rigidbody.AddTorque(0, turnSpeed, 0); 
    } 
    
}

I think might suit your purposes better i think it appears that OnTriggerExit was telling the player to just rotate back again. the OnTriggerStay tells it to just rotate when it detects an object is inside the colision area.

If you are adamant to use the original scripting method try

using UnityEngine; 
using System.Collections; 

public class Feeler_GD : MonoBehaviour 
{ 
    public GameObject player; 
    public float turnSpeed; 

    void OnTriggerEnter(Collider other) 
    { 
        player.rigidbody.AddTorque(0, turnSpeed, 0); 
    } 
    void onTriggerExit(Collider other) 
    { 
        player.rigidbody.AddTorque(0, 0, 0); 
    } 

}