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
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
3 жыл бұрын
could I make the enemy go faster at all?
@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
3 жыл бұрын
@@fui5982 Thankyou! this helps alot!
@fui5982
3 жыл бұрын
@Anon Anon K man dont really care now
@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!
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
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
3 жыл бұрын
Glad you enjoyed!!!!!
Very short and efficient! Thank you!
Hey thanks, I needed the script and this was simple and to the point
This actually helped me out sooo much dude, thanks alot! Now I can finish my VR game.
@fui5982
3 жыл бұрын
I gotchu mate
@ithinkartisfun2897
2 жыл бұрын
@@fui5982 Idk what i did wrong but the script is inverted, it makes the player follow the enemy
@kravataf
2 жыл бұрын
@@ithinkartisfun2897 what the
@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
Жыл бұрын
Same I’m making a vr game to
thank you so much ive been looking for days and this was the only one that worked thank you
never knew it was this simple, thank you
Thank you so much. I tried for hours, but this actually worked.
That's the first time it worked for me, it's so nice that u made it, thanks.
Thank you thank you THANK YOU!!!!! I can now finish my game!!! YOU ARE A LEGEND!!!!
This was the only tutorial that was helpful. You earned a sub.
Thanks a lot man, this really helped out with my class project!
Thanks. this worked well! I thought it would be more complicated than this!
Thanks for the help. Worked perfectly.
YES just what i was looking for
easily the most simple tutorial on that matter!
Thank you!
Super helpful and easy to understand!
Dude u made my work so easy thank u :)
Thanks you so much This helped me so much :D
Thank you! really simple explanation
Thank you this is awesome!
ive been wanting to make a game with enimies now this vid helped alot
simple instruction thank you still works in new version
thank you, this was so helpful
Thanks!! it really works
thanks!! its very simple and easy to follow!!😀
Thanks my g, Like the way how you did explain everything :))
thx, im making a sonic fangame so you know i needed this, ima check if it works
Excellent, thank you!
man, this is perfect
Really helpful for beginners
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
2 жыл бұрын
lifesaver
@aryantyagi100
2 жыл бұрын
Dude, thanks so much!
@dawaysss7987
Жыл бұрын
how do i mark it as static?
@SnortSnout64
Жыл бұрын
@@dawaysss7987 select the object. there should be a checkbox in the upper right corner of the inspector to mark it as static.
thanks ur tutorial work in my project
Thank you sooooooooooooooooooooooooooooooooo much for making this video, got the cube to chase my player. Love it😁😁🚀🚀🚀🚀🚀🏆🏆🏆🏆🏆🏆🎮🎮🎮🎮🕹🕹🕹🕹🕹
Thank you very much!!! ❤❤❤
Thanks! Nice Video :D
omg this is what im looking for!!
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?
Amazing!
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.
Great job, subscribed
@fui5982
3 жыл бұрын
you are officially awesome!
Thx so much my friend
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
I don't manage to get it working if i'm instantiating the enemy during gameplay. Do you have any suggestion? Thanks!
Can you make a video on how to make the AI roam and attack when close
fantastic!
this video deserves a sub!!!
Thanks so much!! I would download the game, but i don't have an android...
Nice tutorial
Cool :)
Thank you
thanks this helped and i got the game
@fui5982
2 жыл бұрын
Ey man you didn't have to but thanks anyway
@theordinaryduck
2 жыл бұрын
because i have been stuck on this for ages
How come when I write the script i cant set references?
Hey I need help! For some reason i cant put my enemy into the NavMeshAgent.
thnx for the video
Yes it worked 👍
THANK YOU THIS IS MAGIC
@InfiniteCodeSource
Жыл бұрын
how did you get the references
@twistedsluggerdev
Жыл бұрын
@@InfiniteCodeSource wdym?
Thank you brother
Thanks😊
If we don't generate the capsule object as prefab, Is enemy gonna follow the capsule object at the same time ?
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.
My Nav Mesh runs away from the destination? Do you know what could cause this?
Is the player moving to where we click position plz help
Thanks!
Thank you.
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?
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."
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
How can we change the speed of enemy
i can't find the navigation static
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?
Thanks👍🏿
Thanks for the tutorial, I Was wondering if I can make the enemy to follow me only from a certain distance.
@scriptod91
2 жыл бұрын
Yes you can! try if (Vector3.Distance(transform.position, target.position) { agent.SetDestination(target.position); }
@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
2 жыл бұрын
@@scriptod91 Thank you so much!!
Kinda late to this but I’m unable to add any references
This is great, is it possible to set a max follow distance?
@Tail1704
Жыл бұрын
Yes but you have to make a wander script too if you do what I'm think you're trying to do
Yo can anyone put the code in the comments? I can't see anything. The screen recording is a bit mid.
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
3 ай бұрын
Don't type "transform" type "Transform
thx:)
my character only spins, it does not move with my character ??
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
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
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
2 жыл бұрын
@@fui5982 still not working
@Hackets
2 жыл бұрын
@@manavpoudel3980 then cry
@xermi00
Жыл бұрын
@@manavpoudel3980 static has to be checked
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
@Fui can you make a simple ai attack like this>?
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
2 жыл бұрын
@LeonYT Games Thank you❤
@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.
Thank you! I wonder if I have a human form enemy, will it always be standing up
@fui5982
2 жыл бұрын
It should as long as your human model is oriented and rotated properly.
@joelastorga7548
2 жыл бұрын
@@fui5982 thanks!!
Make a video where enemy cannot see the player when there is a wall between them
could Movetowards work?
I've downloaded ur game man
how to do this with more enemys
that blue doesnt show up
Thanks
It’s not like a enemy, it’s more of a pet, a cute one
@fui5982
3 жыл бұрын
yeah
I did everything right, but the console shows so much errors
it worked
Anyone knows how to make the same thing in godot?
how to make huge number enemy chase player
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
3 жыл бұрын
I think I got a fix
@nissyyybeatz
2 жыл бұрын
are you albanian
ok my enemy is following player but not doing animation(walking animation) what should i do ?
@MessaTheDev
Жыл бұрын
step 1: make enemy animation step 2: SCRIPT THE ANIMATION GODDAMN step 3: profit
its not working the enemy is not moving at all