How to make an enemy follow player - Unity NavMesh

Тәжірибелік нұсқаулар және стиль

This video will cover how to make an enemy follow our player using unity's navmesh component.
Download My Game
play.google.com/store/apps/de...
Download Standard Assets
assetstore.unity.com/packages...
📺SUBSCRIBE TO THE CHANNEL TO LEARN MORE
/ @fui5982

Пікірлер: 225

  • @fui5982
    @fui59823 жыл бұрын

    Hey everyone I do want to mention that you have to click navigation static in the object tab in the navigation window. This will actually allow you to click bake.(Sorry for the video quality its one of my older ones).

  • @VirusFusion

    @VirusFusion

    3 жыл бұрын

    could I make the enemy go faster at all?

  • @fui5982

    @fui5982

    3 жыл бұрын

    Yes, you can change the speed value under steering in the Nav Mesh Agent Component in the inspector. Or if you want to change the speed via script just get a reference to the navmeshagent in our case its the variable enemy. You can then set the enemy.speed to what ever float value you would like. Hopefully this makes sense.

  • @VirusFusion

    @VirusFusion

    3 жыл бұрын

    @@fui5982 Thankyou! this helps alot!

  • @fui5982

    @fui5982

    3 жыл бұрын

    @Anon Anon K man dont really care now

  • @Nico-xs2lq

    @Nico-xs2lq

    3 жыл бұрын

    I make a test to see how good is it, the problem that it does not jump but litteraly just go trought the ground and if there is a wall he is not going to like go around the wall to get to you, but its just a small error that you can fix putting a ramp and dont having walls on your level or map, but its pretty cool!

  • @maxchristianheinrichflinke2571
    @maxchristianheinrichflinke2571 Жыл бұрын

    Thank you. A line of code me lacked for 4 hours found through this content. Best video of my lifetime thus far from current perspective

  • @holdenmitchell4710
    @holdenmitchell47103 жыл бұрын

    this was amazing and i especially liked how you went through evrything and told us where to find the controller and stuff thanks dude im new to unity and this helped so much i dont have an android but i might get one soon ill check out ur game

  • @fui5982

    @fui5982

    3 жыл бұрын

    Glad you enjoyed!!!!!

  • @negi121
    @negi1212 жыл бұрын

    Very short and efficient! Thank you!

  • @rukhmannhayer5672
    @rukhmannhayer56723 жыл бұрын

    Hey thanks, I needed the script and this was simple and to the point

  • @hiddnfox
    @hiddnfox3 жыл бұрын

    This actually helped me out sooo much dude, thanks alot! Now I can finish my VR game.

  • @fui5982

    @fui5982

    3 жыл бұрын

    I gotchu mate

  • @ithinkartisfun2897

    @ithinkartisfun2897

    2 жыл бұрын

    @@fui5982 Idk what i did wrong but the script is inverted, it makes the player follow the enemy

  • @kravataf

    @kravataf

    2 жыл бұрын

    @@ithinkartisfun2897 what the

  • @Kaito..763

    @Kaito..763

    2 жыл бұрын

    @@ithinkartisfun2897 try putting the enemy script on the enemy, and remove it from the player so the enemy will follow the player

  • @SkullClanReal

    @SkullClanReal

    Жыл бұрын

    Same I’m making a vr game to

  • @Indertorcraft
    @Indertorcraft2 жыл бұрын

    thank you so much ive been looking for days and this was the only one that worked thank you

  • @Jaydenbb5
    @Jaydenbb5 Жыл бұрын

    never knew it was this simple, thank you

  • @AviSnow
    @AviSnow2 жыл бұрын

    Thank you so much. I tried for hours, but this actually worked.

  • @einJFK
    @einJFK Жыл бұрын

    That's the first time it worked for me, it's so nice that u made it, thanks.

  • @mrnlng
    @mrnlng3 жыл бұрын

    Thank you thank you THANK YOU!!!!! I can now finish my game!!! YOU ARE A LEGEND!!!!

  • @rasulkhani
    @rasulkhani7 ай бұрын

    This was the only tutorial that was helpful. You earned a sub.

  • @thelastraikage
    @thelastraikage2 жыл бұрын

    Thanks a lot man, this really helped out with my class project!

  • @CapybaraStudios
    @CapybaraStudios Жыл бұрын

    Thanks. this worked well! I thought it would be more complicated than this!

  • @wizardkot2052
    @wizardkot20522 жыл бұрын

    Thanks for the help. Worked perfectly.

  • @ExoticElephantStudios
    @ExoticElephantStudios3 жыл бұрын

    YES just what i was looking for

  • @vfx.360
    @vfx.3602 жыл бұрын

    easily the most simple tutorial on that matter!

  • @GlitchVR
    @GlitchVR3 жыл бұрын

    Thank you!

  • @shawneemepham7001
    @shawneemepham7001 Жыл бұрын

    Super helpful and easy to understand!

  • @adaboykrisiboy36
    @adaboykrisiboy363 жыл бұрын

    Dude u made my work so easy thank u :)

  • @nicolaisneftrup1111
    @nicolaisneftrup11113 жыл бұрын

    Thanks you so much This helped me so much :D

  • @acikgozemre
    @acikgozemre3 жыл бұрын

    Thank you! really simple explanation

  • @vojinjanjic8414
    @vojinjanjic84143 жыл бұрын

    Thank you this is awesome!

  • @rockyoverton2175
    @rockyoverton21752 жыл бұрын

    ive been wanting to make a game with enimies now this vid helped alot

  • @pocoace5415
    @pocoace541511 ай бұрын

    simple instruction thank you still works in new version

  • @fishy2423
    @fishy24232 жыл бұрын

    thank you, this was so helpful

  • @anasjohnson9058
    @anasjohnson90583 жыл бұрын

    Thanks!! it really works

  • @kimzamusic
    @kimzamusic2 жыл бұрын

    thanks!! its very simple and easy to follow!!😀

  • @kutpetj
    @kutpetj2 жыл бұрын

    Thanks my g, Like the way how you did explain everything :))

  • @SNBreal
    @SNBreal3 жыл бұрын

    thx, im making a sonic fangame so you know i needed this, ima check if it works

  • @rogersun6184
    @rogersun6184 Жыл бұрын

    Excellent, thank you!

  • @brk3451
    @brk34513 жыл бұрын

    man, this is perfect

  • @gauravpatkar1946
    @gauravpatkar19463 жыл бұрын

    Really helpful for beginners

  • @SnortSnout64
    @SnortSnout642 жыл бұрын

    Thank you, one thing to note though is that your terrain has to be marked as static, otherwise baking the navmesh wont build the navmesh for it.

  • @mugz1822

    @mugz1822

    2 жыл бұрын

    lifesaver

  • @aryantyagi100

    @aryantyagi100

    2 жыл бұрын

    Dude, thanks so much!

  • @dawaysss7987

    @dawaysss7987

    Жыл бұрын

    how do i mark it as static?

  • @SnortSnout64

    @SnortSnout64

    Жыл бұрын

    @@dawaysss7987 select the object. there should be a checkbox in the upper right corner of the inspector to mark it as static.

  • @arbiirfa2080
    @arbiirfa20803 жыл бұрын

    thanks ur tutorial work in my project

  • @Nick-rq4gy
    @Nick-rq4gy3 жыл бұрын

    Thank you sooooooooooooooooooooooooooooooooo much for making this video, got the cube to chase my player. Love it😁😁🚀🚀🚀🚀🚀🏆🏆🏆🏆🏆🏆🎮🎮🎮🎮🕹🕹🕹🕹🕹

  • @fives1734
    @fives17342 жыл бұрын

    Thank you very much!!! ❤❤❤

  • @amees89
    @amees893 жыл бұрын

    Thanks! Nice Video :D

  • @yetongggg
    @yetongggg11 ай бұрын

    omg this is what im looking for!!

  • @warrior-e_x_e1240
    @warrior-e_x_e12402 жыл бұрын

    so for some reason whenever i put the code into the editor and i put it on my enemy it shows the script but not the enemy or player choosing things?

  • @otamatonegaming
    @otamatonegaming3 жыл бұрын

    Amazing!

  • @aldopetruzzelli849
    @aldopetruzzelli849 Жыл бұрын

    I can't seem to be able to assign the enemy and the player to the characters. Is there something missing? Also the autocorrect on Unity made me do some changes to the code.

  • @SquareOneTutorials2020
    @SquareOneTutorials20203 жыл бұрын

    Great job, subscribed

  • @fui5982

    @fui5982

    3 жыл бұрын

    you are officially awesome!

  • @gmangman123
    @gmangman1233 жыл бұрын

    Thx so much my friend

  • @JPGpack
    @JPGpack Жыл бұрын

    is there a way to make it spawn after walking on an area in the floor and then making it despawn after you step on another area on the floor like a start line and finish line but the enemy is chasing you when you spawn it and then despawn it

  • @ErsinBactisa
    @ErsinBactisa2 жыл бұрын

    I don't manage to get it working if i'm instantiating the enemy during gameplay. Do you have any suggestion? Thanks!

  • @edoga8895
    @edoga88953 жыл бұрын

    Can you make a video on how to make the AI roam and attack when close

  • @hefferwolff3578
    @hefferwolff357828 күн бұрын

    fantastic!

  • @user-mk6eb7ui5w
    @user-mk6eb7ui5w8 ай бұрын

    this video deserves a sub!!!

  • @kaden007
    @kaden0073 жыл бұрын

    Thanks so much!! I would download the game, but i don't have an android...

  • @ishitadubey9502
    @ishitadubey95023 жыл бұрын

    Nice tutorial

  • @juba3061
    @juba30613 жыл бұрын

    Cool :)

  • @LEASER69
    @LEASER69 Жыл бұрын

    Thank you

  • @theordinaryduck
    @theordinaryduck2 жыл бұрын

    thanks this helped and i got the game

  • @fui5982

    @fui5982

    2 жыл бұрын

    Ey man you didn't have to but thanks anyway

  • @theordinaryduck

    @theordinaryduck

    2 жыл бұрын

    because i have been stuck on this for ages

  • @halfalive145
    @halfalive1453 жыл бұрын

    How come when I write the script i cant set references?

  • @karrpclips2679
    @karrpclips2679 Жыл бұрын

    Hey I need help! For some reason i cant put my enemy into the NavMeshAgent.

  • @foxGameDev-dk1se
    @foxGameDev-dk1se27 күн бұрын

    thnx for the video

  • @KikiKilo
    @KikiKilo Жыл бұрын

    Yes it worked 👍

  • @twistedsluggerdev
    @twistedsluggerdev Жыл бұрын

    THANK YOU THIS IS MAGIC

  • @InfiniteCodeSource

    @InfiniteCodeSource

    Жыл бұрын

    how did you get the references

  • @twistedsluggerdev

    @twistedsluggerdev

    Жыл бұрын

    @@InfiniteCodeSource wdym?

  • @md.ratulislam7759
    @md.ratulislam7759 Жыл бұрын

    Thank you brother

  • @ArumugaTamilSelvan
    @ArumugaTamilSelvan Жыл бұрын

    Thanks😊

  • @enes6223
    @enes6223 Жыл бұрын

    If we don't generate the capsule object as prefab, Is enemy gonna follow the capsule object at the same time ?

  • @bluumishh
    @bluumishh3 жыл бұрын

    I may be doing something wrong, but it is not working for me. When i try to put it on my enemy it just would throw an error to my face.

  • @theledip
    @theledip2 жыл бұрын

    My Nav Mesh runs away from the destination? Do you know what could cause this?

  • @satishkumar-ol3kb
    @satishkumar-ol3kb3 жыл бұрын

    Is the player moving to where we click position plz help

  • @leonelmendoza1229
    @leonelmendoza12292 жыл бұрын

    Thanks!

  • @taehyeong94
    @taehyeong9410 ай бұрын

    Thank you.

  • @valarizz
    @valarizz Жыл бұрын

    I did everything right but unity sais me " "SetDestination" can only be called on an active agent that has been placed on a NavMesh." what should I do?

  • @muhammadumair-ql5sm
    @muhammadumair-ql5sm2 жыл бұрын

    well i did what you did and I got this error "can only be called on an active agent that has been placed on a NavMesh."

  • @Miguel-td8kh
    @Miguel-td8khАй бұрын

    Every time I try to play the game it says all compile errors have to be fixed idk what to do any help? I’ve checked my code and everything is good there

  • @charanreddy8675
    @charanreddy86752 жыл бұрын

    How can we change the speed of enemy

  • @scottplayz453
    @scottplayz4533 жыл бұрын

    i can't find the navigation static

  • @camdenburke9268
    @camdenburke92682 жыл бұрын

    I followed the whole tutorial but at the end my enemy just fell over and didn’t move? Does anyone know what I did wrong?

  • @Opportunerex4
    @Opportunerex4 Жыл бұрын

    Thanks👍🏿

  • @1hr399
    @1hr3992 жыл бұрын

    Thanks for the tutorial, I Was wondering if I can make the enemy to follow me only from a certain distance.

  • @scriptod91

    @scriptod91

    2 жыл бұрын

    Yes you can! try if (Vector3.Distance(transform.position, target.position) { agent.SetDestination(target.position); }

  • @scriptod91

    @scriptod91

    2 жыл бұрын

    Also you have to do public float radius; at the top near public Transform target; and then edit the radius in the menu where you add the player and the enemy

  • @1hr399

    @1hr399

    2 жыл бұрын

    @@scriptod91 Thank you so much!!

  • @InfiniteCodeSource
    @InfiniteCodeSource Жыл бұрын

    Kinda late to this but I’m unable to add any references

  • @Hello-rh4zw
    @Hello-rh4zw2 жыл бұрын

    This is great, is it possible to set a max follow distance?

  • @Tail1704

    @Tail1704

    Жыл бұрын

    Yes but you have to make a wander script too if you do what I'm think you're trying to do

  • @Thisman-fr
    @Thisman-fr Жыл бұрын

    Yo can anyone put the code in the comments? I can't see anything. The screen recording is a bit mid.

  • @thekralex7046
    @thekralex70462 жыл бұрын

    I have a problem that put: error CS0246 The type or namespace name "transform" could not be found and the icual error but wich MonoBehaviour. pls any help?

  • @Eloram05

    @Eloram05

    3 ай бұрын

    Don't type "transform" type "Transform

  • @vinay4078
    @vinay40783 жыл бұрын

    thx:)

  • @Suavefrench
    @Suavefrench5 ай бұрын

    my character only spins, it does not move with my character ??

  • @pitifulrock630
    @pitifulrock6303 жыл бұрын

    you might not reply but its worth a shot. I get an error in the console saying ""SetDestination" can only be called on an active agent that has been placed on a NavMesh." any help?

  • @fui5982

    @fui5982

    3 жыл бұрын

    Select your surface. Then go to the Navigation window where it says Agents | Areas | Bake | Object . Then select the object tab and select navigation static. Then you should be able to switch over to the Bake settings and hit Bake. Hope this makes sense.

  • @kobe8753

    @kobe8753

    3 жыл бұрын

    @@fui5982 It's been bugging me for 2 hrs already lol, thanks for replying to this and I'm glad I looked in the comment section lol.

  • @manavpoudel3980

    @manavpoudel3980

    2 жыл бұрын

    @@fui5982 still not working

  • @Hackets

    @Hackets

    2 жыл бұрын

    @@manavpoudel3980 then cry

  • @xermi00

    @xermi00

    Жыл бұрын

    @@manavpoudel3980 static has to be checked

  • @tobyconoley5511
    @tobyconoley55118 ай бұрын

    One thing you forgot to mention is make sure the area you adding a nav mesh too is set to Static otherwise it wont work. p.s I know it's old video but still

  • @bonse2000
    @bonse2000 Жыл бұрын

    @Fui can you make a simple ai attack like this>?

  • @touqan5091
    @touqan50913 жыл бұрын

    I also have an error that says Assets\EnemyFollow.cs(19,15): error CS1061: 'NavMeshAgent' does not contain a definition for 'SetDestanation' and no accessible extension method 'SetDestanation' accepting a first argument of type 'NavMeshAgent' could be found (are you missing a using directive or an assembly reference?)

  • @durumvfx

    @durumvfx

    2 жыл бұрын

    @LeonYT Games Thank you❤

  • @xermi00

    @xermi00

    Жыл бұрын

    Hi, I know Im a bit late but I have a solution for that problem. You need to check "static" in your inspector tab and then bake the terrain and all places where the enemy should walk on in "navigation tab" If you don't check "static" first, you are going to see errors in the console and your enemy will stand still all the time. I hope this helps, good luck with your project.

  • @joelastorga7548
    @joelastorga75482 жыл бұрын

    Thank you! I wonder if I have a human form enemy, will it always be standing up

  • @fui5982

    @fui5982

    2 жыл бұрын

    It should as long as your human model is oriented and rotated properly.

  • @joelastorga7548

    @joelastorga7548

    2 жыл бұрын

    @@fui5982 thanks!!

  • @omiorahman6283
    @omiorahman62832 жыл бұрын

    Make a video where enemy cannot see the player when there is a wall between them

  • @chairchairyes2524
    @chairchairyes2524 Жыл бұрын

    could Movetowards work?

  • @user-ze5wz8gy9h
    @user-ze5wz8gy9h Жыл бұрын

    I've downloaded ur game man

  • @BossAleks123
    @BossAleks123 Жыл бұрын

    how to do this with more enemys

  • @exil_s4247
    @exil_s4247 Жыл бұрын

    that blue doesnt show up

  • @kissmulti
    @kissmulti3 жыл бұрын

    Thanks

  • @kenshioya9118
    @kenshioya91183 жыл бұрын

    It’s not like a enemy, it’s more of a pet, a cute one

  • @fui5982

    @fui5982

    3 жыл бұрын

    yeah

  • @Hustlerdan_
    @Hustlerdan_3 жыл бұрын

    I did everything right, but the console shows so much errors

  • @foxGameDev-dk1se
    @foxGameDev-dk1se27 күн бұрын

    it worked

  • @volcano3864
    @volcano38642 жыл бұрын

    Anyone knows how to make the same thing in godot?

  • @digitalmarketingmax
    @digitalmarketingmax11 ай бұрын

    how to make huge number enemy chase player

  • @1993VolkswagenPassatGLXVR6
    @1993VolkswagenPassatGLXVR63 жыл бұрын

    I have this problem where my enemy flies up into the sky, and if there is a rigidbody it falls down while doing a spin. Do you know a fix to that?

  • @1993VolkswagenPassatGLXVR6

    @1993VolkswagenPassatGLXVR6

    3 жыл бұрын

    I think I got a fix

  • @nissyyybeatz

    @nissyyybeatz

    2 жыл бұрын

    are you albanian

  • @rehmanbajwa6766
    @rehmanbajwa67663 жыл бұрын

    ok my enemy is following player but not doing animation(walking animation) what should i do ?

  • @MessaTheDev

    @MessaTheDev

    Жыл бұрын

    step 1: make enemy animation step 2: SCRIPT THE ANIMATION GODDAMN step 3: profit

  • @beastmasterbg
    @beastmasterbg2 жыл бұрын

    its not working the enemy is not moving at all

Келесі