Simple 2D Enemy Patrolling Unity tutorial

preview_player
Показать описание

Enjoy the video, if you have any questions ask in the comments down below!

Request a tutorial here:

Patreon with fully explained c# scripts:

Play my games! :

tutorial,unity tutorial,patrolling enemy,unity 2d patrolling enemy,unity enemy patrol tutorial,unity enemy patrol tutorial 2d,enemy,unity ai tutorial,unity patrolling enemy,patrolling enemy unity,unity patrolling enemy ai,patrolling enemy unity 3d,patrolling,unity 2d tutorial,unity tutorial for beginners,enemy patrol,simple unity tutorial,patrolling enemy ai,unity enemy patrol,bolt tutorial,unity 2d enemy patrol script,unity enemy ai tutorial Audio used in my videos:
♪ Onion (Prod. by Lukrembo)
♪ Branch (Prod. by Lukrembo)
♪ Biscuit (Prod. by Lukrembo)
♪ Bread (Prod. by Lukrembo)
Рекомендации по теме
Комментарии
Автор

The scripts from this video are available here:

morebblakeyyy
Автор

I was planning on making enemies for my first game very soon, this came at the perfect time thank you!❤

guynamedbob
Автор

For those of you having issues, try increasing the float in lines 35 and 40 to a larger number, you may just not be getting close enough to each point. You can control this with a float in your inspector for quick testing :)

bblakeyyy
Автор

absolutely great video! I just recently started leaning how to program (it was actually last weekend) and I must say: you explained everything very good and made it simple, so that even a beginner like me could easily understand it!

madretzlpiano
Автор

thank you so much for this script. I modified it a lot, so when the enemy touches the player, it plays an attack animation that kills the player if the sword touches him, and after the attack, the enemy starts walking again.

Haffey.z
Автор

remember to use composite collider if u are using a tilemap

skyr
Автор

Yesh! it worked, thank you so much for the tutorial :DD

ChrismisHere
Автор

thanks! this helped me do something i have wanted to do for a long time!

pureegaming
Автор

Thanks a lot man, you really saved my timed Project, lots of love <3

gzerem
Автор

To those who want to add a flip onto their sprite, add this bit of code to your first "If" and "Else" statement.

transform.localScale = new Vector3(-1, 1, 1);
transform.localScale = new Vector3(1, 1, 1);

Put it above your "rb.Velocity" code. If your sprite goes backwards then just flip the -1 to the other statement

hanpolo
Автор

Hi thank you so much for the help it worked for my game! I would love to see a video where you explain how to make the enemies idle for some seconds then move again though if it's possible sometime! Thanks for this brilliant video tutorial!

sayhan
Автор

for some reason the if (currentpoint == point.transform) is not working correctly at all. I fixed this by making the speed switch direction in the second set of ifs (the ones that check the distance) and always have the velocity at speed.

valonyaver
Автор

The caracter doesn't stop at point B and I don't know why because I did everything coorectly. Can someone help me pls ?

blackmd
Автор

What do I do if I want to add 2 and more patrolling enemies? Code works only for one enemy. Do I need to add a different script for each new enemy?

ilya_rusin
Автор

I copied this code minus the animation related things on unity, and all it does is make my enemy move until it hits a 2D box collider. Are the anim codes necessary even if you don't have animation frames yet?

firewarrior
Автор

hey, the code works but I have the following Issue: If I set let's say the enemy as a parent Object and move the points under it, the code stops working and it just moves past the points

mohsen
Автор

ia nayone could help i got to the stage before flipping the enemy but my character still walks off the edge any fixes?

SixFlickz
Автор

Life saver, I was doing it by have two trigger blocks at the end and when it enters the trigger block it reverses the direction

SLLicant
Автор

Why does mine randomly stop after turning? After if give it a push with my player it starts moving again tho

skiwii
Автор

Very good tutorial! works good, i wonder if there is a way to make it so that the enemy can jump up a little step if needed so it can patrol larger area

xonestly
visit shbcf.ru