Uploaded October 2020 | Updated September 2026, 3 weeks ago
#UnityEnemy #AmongUs #UntiyFollow
Episode 5. Make Enemy Follow The Player In 2D Top Down Game Like Among Us Shooter Clone Made With Unity.
I play games here - twitch.tv/zzotoff
You are very welcome :-)
Previous Video
Create Enemy Run Animation For Among Us 2D Shooter Game Clone Made With Unity Software youtu.be/9OV_M5PpjPY
Pre-Previous Video
Fire Pistol And Shotgun Switching Them Back And Forth | Unity Fire And Switch Weapon Tutorial youtu.be/vmbZsbdqza0
Pre-Pre-Previous video
Give Among Us A Weapon Pistol & Shotgun | Game Clone Made In Unity Software | Weapon Switch Feature youtu.be/nDAZIKNx0wg
Pre-Pre-Pre-previous video
Among Us Idle And Run Animation Unity Software Tutorial | Top Down Movement In 2D Unity Game youtu.be/W3-EncfpBZM
Hi!
In this video I show you a very simple script that can make an enemy follow the player. The enemy is red and the player is blue in this case. Kind of homing enemy.
Ok. Here is my project which I’ve been creating for several videos by now. You can find links to previous videos in the description. So here I have a character and an enemy. In fact it's a pretty simple task to make this enemy follow the character. This script will help me to do so.
Here are some variables. In the start method I get a rigidbody component. I find a gameobject which has the Player script attached. This game object will be the target. I’ll attach that Player script to my character later. Set move speed and get local scale to face the enemy towards the direction it goes. In fixed update I move the enemy. First I get direction to Player. And then just give a velocity towards the player. Pretty simple. And in late update I face the enemy left or right depending on where it goes. That’s the script. I D&D this script to enemy. To make it move I have to add a rigidbody 2d to it. I do so and set the gravity scale to 0 so the enemy will not fall down. The final step to make my enemy move towards the player is to D&D player script into my character. This script is empty by the way. No special code there. Just default lines which are created along with the script. Let’s hit play and check it out. Enemy follows the player. But here is one little issue. The enemy goes to the lower part of the character but not to the center of it. This happens because of the fact that I shifted characters pivot point to the bottom of its sprite in the very first video. I did it for the sake of animation jitterlessness. I hope this word exists. At least it does now. Enemies pivot point is in the center. So simply saying pivot point of enemy goes towards players pivot point. That’s why I have this issue. There are a lot of way to fix it. What I came up with is to add a child gameobject to the character and give it that player script. So I remove player script from the character. Add a new empty child to it. Name it as Player. And position it right about at the center of the character. Here. And I D&D player script to the player gameobject. So the enemy will follow this game object now. Let’s check it out. Nice! Hope you like this tutorial. Thank you for watching and see you next time.
#UnityEnemy #AmongUs #UntiyFollow
Episode 5. Make Enemy Follow The Player In 2D Top Down Game Like Among Us Shooter Clone Made With Unity.
I play games here - twitch.tv/zzotoff
You are very welcome :-)
Previous Video
Create Enemy Run Animation For Among Us 2D Shooter Game Clone Made With Unity Software youtu.be/9OV_M5PpjPY
Pre-Previous Video
Fire Pistol And Shotgun Switching Them Back And Forth | Unity Fire And Switch Weapon Tutorial youtu.be/vmbZsbdqza0
Pre-Pre-Previous video
Give Among Us A Weapon Pistol & Shotgun | Game Clone Made In Unity Software | Weapon Switch Feature youtu.be/nDAZIKNx0wg
Pre-Pre-Pre-previous video
Among Us Idle And Run Animation Unity Software Tutorial | Top Down Movement In 2D Unity Game youtu.be/W3-EncfpBZM
Hi!
In this video I show you a very simple script that can make an enemy follow the player. The enemy is red and the player is blue in this case. Kind of homing enemy.
Ok. Here is my project which I’ve been creating for several videos by now. You can find links to previous videos in the description. So here I have a character and an enemy. In fact it's a pretty simple task to make this enemy follow the character. This script will help me to do so.
Here are some variables. In the start method I get a rigidbody component. I find a gameobject which has the Player script attached. This game object will be the target. I’ll attach that Player script to my character later. Set move speed and get local scale to face the enemy towards the direction it goes. In fixed update I move the enemy. First I get direction to Player. And then just give a velocity towards the player. Pretty simple. And in late update I face the enemy left or right depending on where it goes. That’s the script. I D&D this script to enemy. To make it move I have to add a rigidbody 2d to it. I do so and set the gravity scale to 0 so the enemy will not fall down. The final step to make my enemy move towards the player is to D&D player script into my character. This script is empty by the way. No special code there. Just default lines which are created along with the script. Let’s hit play and check it out. Enemy follows the player. But here is one little issue. The enemy goes to the lower part of the character but not to the center of it. This happens because of the fact that I shifted characters pivot point to the bottom of its sprite in the very first video. I did it for the sake of animation jitterlessness. I hope this word exists. At least it does now. Enemies pivot point is in the center. So simply saying pivot point of enemy goes towards players pivot point. That’s why I have this issue. There are a lot of way to fix it. What I came up with is to add a child gameobject to the character and give it that player script. So I remove player script from the character. Add a new empty child to it. Name it as Player. And position it right about at the center of the character. Here. And I D&D player script to the player gameobject. So the enemy will follow this game object now. Let’s check it out. Nice! Hope you like this tutorial. Thank you for watching and see you next time.










