A script that doesn't allow moving objects to go through non-moving objects?

I have a player, a zombie, and walls.
The player does not go through walls or the zombie. The zombie goes through walls.
Movement script:

var target : Transform;
var moveSpeed = 20;
var rotationSpeed = 5;
var myTransform : Transform;

function Awake() {
        myTransform = transform;
}
 
function Start() {
 
        target = GameObject.FindWithTag("Player").transform;
}
 
function Update () {
   
    myTransform.rotation = Quaternion.Slerp(myTransform.rotation,
    Quaternion.LookRotation(target.position - myTransform.position), rotationSpeed*Time.deltaTime);
    myTransform.position += myTransform.forward * moveSpeed * Time.deltaTime;
}

I no longer care what the script is, as long as it works.
Can someone please respond?

I suggest you reuse the movement script from the player as it already works as intended.

Then, make the zombie control the movement script to navigate toward the player, and make sure your player has a script that control the movement script on the player.

  • PlayerInput directs Movement script on Player game object
  • ZombieAI directs Movement script on Zombie game object
  • I guess your Movement script already controls a rigidbody or something, so make sure both the Zombie and Player have the necessary colliders and rigidbodies and whatever else it needs.

It sounds like movement is pretty much the same with the thing that differ being input method. One is algorithmic (Zombie) and one is driven by input (Player). Makes sense?