I have a problem that might be related to this lecture

Hi guys, I’m trying to make a zombie that can chase the player… I’m kinda new in using C# but from my logical perspective the code is looking ok-ish :)) … The problem that I have is that the zombie is getting out of the map, and I don’t really know if that happens bcs of my code… or of the interactions between the gameobjects. Thanks for your precious time! :slight_smile:


Hi Nistor,

First of all, it’s great to see that you are trying to apply your knowledge. :slight_smile:

From what I see in your screenshots, you are on the right track. Since Unity has no conception of zombies, players, and so on, how does the ZombieRunning object know which game object it is supposed to chase?

transform.position refers to the position of the game object to which the current script instance (component) is attached. Depending on the context, it can reference (“link”) different objects. Furthermore, objects do not know the content of other objects.

As aforementioned, your code looks already good but I feel something is missing. Since you are challenging yourself, I don’t want to tell you the solution right away because it might be that you prefer to figure it out yourself. It’s not that complicated but it might be that you don’t know yet how to accomplish certain things in Unity.

For future reference, please share code as formatted text because that makes it easier to read it, and it would allow us to copy and paste from it.


1 Like

Thanks for your reply!

The thing is that the Running script is component of the player (the runner). I tried to stack his position in a variable that can be accessed from another script (in that case, I wanted to access it in the ZombieRunner script), and move the object (zombie) to the other one’s (player) position, by using that variable (a vector3 type)…

I made a video, maybe it’s useful: https://youtu.be/IJh6azlzTEg

Edit: Nevermind, I actually find out how to resolve it, but with your help! :slight_smile:

This topic was automatically closed 24 hours after the last reply. New replies are no longer allowed.

Privacy & Terms