AI Sight Detection And Chase With Music - Unreal Engine 4 Tutorial
Вставка
- Опубліковано 30 лип 2024
- Hey guys, in today's video, I'm going to be showing you how to create an AI which can detect the player through sight and then start chasing the player, while playing chase music in the background. This will then fade out when the AI can no longer see the player and isn't chasing anymore.
Chase Music: freesound.org/people/burning-...
#Ue4 #UnrealEngine4 #Ue4Tutorial #Horror
___________________________________________________________________________
00:00 - Intro
00:15 - Overview
00:49 - Tutorial
10:17 - Final Overview
10:33 - Outro
___________________________________________________________________________
Unreal Engine 4 Tutorials Playlist: • Unreal Engine 4 Tutorials
The Basics Of Nodes Playlist: • The Basics Of Nodes In...
Blender Tutorials Playlist: • Blender Tutorials
___________________________________________________________________________
If you enjoy make sure to subscribe: / @mattaspland
Join My Discord Server: / discord
Follow Me On Instagram: / matt_aspland_
___________________________________________________________________________
If you want to support me, you can PayPal me at "matt.aspland.1@gmail.com". This is by no means expected or required. It is just a nice support :)
Link to PayPal: www.paypal.com/
You can also support me on Ko-Fi following this link: ko-fi.com/mattaspland
Thank you :) ___________________________________________________________________________
♫Music By♫
●Kronicle - Chill Noons
●Soundcloud - / the-chemist-10
Hey guys, with the delay at 06:35, in between the two branches for "CanSeeEnemy?". If you increase the duration, the player has to be hidden from the AI for longer before the AI loses sight. So increase the duration as much as you like for different effects and difficulties. Or if you think it is losing you too quickly.
The Ai doesnt stop chasing me. I tried to change delay but Ai keep following me :( what can i do?
@@lexxrelaxx2016 same
@@bassboot5357 I think, it is because the AIMoveTo function does not stop until it gets to your position or is not able to get there (like you are out of nav mesh). Anyway to fix it, call StopActiveMovement function on AI character, when you stop music.
@@MrChick1984 Thank you so mutch! Thats just what i searched for!
@@lexxrelaxx2016 i had the same problem but i fixed it
You are a legend, thanks for these tutorials!
Thank you man, no problem, happy to help! :)
Thank you so much for this.
Your helping me very much I did not want to make a game in UE4 but your tutorials are very good.
Thank you again my fiend.
No problem, I'm happy I can help you, no problem and best of luck of luck with your game :)
I didn't know you could do all this without the behavior tree. Wow, thank you.
Yep, I find it easier to understand like this. No problem :)
Lets goooo great as always my man
Thank you so much! :)
Thank god, I was searching this tutorial for day
These are by far the best Unreal Engine tutorials I've found and I've been searching night and day
Thanks so much man! Always happy to help! :)
On god
true
Your search is now over my son. You have reached your final destination, total enlightenment and immortality...
You are A Great Teacher!! thank you for your great detailed tutorial, much needed, concise and practical , appreciate all of them!!! Still, if you could please consider explain for a few sentences the objectives(as small intermediate steps to achieve the final objective) each time before you start doing something (i.e. start blueprinting) , then your tutorial will be perfect, the most helpful way for us noobs to quickly learn is to follow your thought process before implement the coding. Thankfully You did this but mostly at the end of the coding , a reverse of the teaching order can significantly reduce the learning time for idiots like me. again, thank you very much. God bless
thanks i really like your videos you help me a lot
Hi matt. Love the ai chase videos. Can you do a tutorial where there are 2 different modes, neutral and hunt, so when the ai sees the player then goes out of chase mode it looks around the area for a minute or 2 then go back to neutral?
Amazing tutorial!! It's so creepy
Thanks for making that video it will help me alot me in horror game liked your video
No problem, happy to help :)
literally first working tutorial on ai
In case anyone else has the problem where it chases you after it shouldn’t be able to, just add a retriggerable delay after the “set” that changes “can see enemy?” to false and change it to what time you want him to give up after and then a “stop active movement” and it’ll stop chasing you
ty
Hey thank you that was really helpfull
@@Balkor glad I could help!
you are awesome, helped me so much for my class lol
Glad I could help!
Thank you man
Amazing. I love you video
this is a great tutorial! This is one step for me on my backrooms game!
I hope you succeed!
Thank you!
awesome thank you matt :)
Thank you and no problem man :)
Brilliant tutorial
Thank you so much!
Hey great tutorial. Is there any way to lower the volume of the music?
My Mr X AI is gonna be juicy with that tutorial! Can you make a tutorial on how to make enemy spawn randomly in selected area? Kinda like mr x or any game with chase enemy (phasmohpobia, hello neighbor)
Hey, of course yeah, I can look into that :)
Thanks it works
Hi Matt, thank you VERY much for the tut. Your style is clean, but not as clean as your pronunciation! I hope you are still reading your comments... how would you deal with multiple enemy sound overlap? I have multiple enemy spawns in the level and the sound clip overlaps, creating a cacophony! I will try to solve, but would appreciate a tip. Thanks again, even if you don't reply.
THANK YOU!!!!!
Thank u so much i thoght theres problme in this way because when enemy chasing you he will leave you never in the nav volume ..Until I saw the second part
Hi Matt. I've got this working, but suppose there are 2+ AIs. I want it to be the case that when both are chasing me, there aren't 2 audio tracks trying to play over one another. I was wondering if it was possible to have "World Music" playing upon being chased. When you can, let me know your thoughts on the matter and if it's way more overhead than I'm thinking
Hey. Tutorial is great and the chase works perfectly fine, but I have one issue.
When the ai is chasing me and I’m from a far away distance, the music glitches in and out, but when I’m close to the ai, the music is fine.
Any way to fix this?
Yes😁 Do more AI stuff, iam waiting for behavior tree😁😁
Thank you, I'll hopefully get around to it, but I plan on doing more definitely :)
Behaviour trees confuse the hell out of me, I don't know if to keep building on a basic A.I in BP or you mix the two ?
@@Si-Toecutter The way Matt showed how to set up the AI in this video is decent, but when you begin to place hundreds of characters on your level/map, with an AI logic for each of them, that can start getting quite heavy.
What you should do is create and attach an AI component to the ennemy blueprint, create a behavior tree, and run the behavior tree on the begin play event in the AI component.
Try avoid building the logic inside each AI character, build it in the behavior tree.
Nice tutorial bruh, I like the Metal Gear Solid wannabe chase music lmaoooo
Would this work with multiple AI? Like A horde of zombie detect you, And you kill one, Would it stop all music? Would the music start again for each zombie that detects you? Would it stop when all are killed or just one? I've implemented this in some of my other games, but can't get it working consistently.
Hey Matt, quick question. I created the ai petrolling blueprints first and now i create this chase bps but my ai doesnt chase me. on see pawn doesnt and i tried to connect them but i cant. how can i do that whats the problem
Hey, thank you for your tutorials!
I'm currently working on a Uni project...I created my project using the Advanced Locomotion V4 in store.
I have my enemies starting in a rag-doll state, I've followed your tutorial from there.
My enemies don't move at all, instead they just stay in whichever state ive selected them to be in.
I could send photos of my blueprints?
thank you in advance :D
Hey mate, one thing I'll say is, have you got a nav mesh placed down? If so, if you press "P", does the floor turn green where the AI should move?
If both of those are yes, then yeah you can send me some screenshots of your blueprints. You can send them to my email, which can be found on my about page.
Or you could also copy and paste your code to this website, and send the link back :)
blueprintue.com/
hey!! great tutorial but im having a problem when the enemy sees me it does play the music but it keeps restarting after every second?
It's it bad to have all this run on tick? (also the part 2 video).. I mean, doesn't it fire off this code on every tick?
I imported the base third person assets into the first person base, I believe I followed all your steps but the only thing I changed was "Cast to first person Character" instead of "cast to third person Character" but it seems the AI is not moving. Why would this be? The detection and music is fine though for some reason. anyone could help me?
ok so my giant ghost sees player, chases him, he hides, chase ends.... AND I THEN MAKE THE GHOST TELEPORT TO ANOTHER FLOOR, to do this all over again, at the most inopportune time possible.
how do i do that?
One question
How can i make to play 2 soundtracks
1 for when he is chassing and on for when he is not chassing
Noice ty
Thank you and no problem :)
Awesome bro, but I have a problem.. in my game there are 3 AI, when any of them find you it starts playing the sound I put for chase, but when two find me at the same time, the sound plays mixed :/
Hi Matt thanks for the great tutorial! I was just wondering what the best way is to go about storing a reference for multiple sounds? I notice you can only use the "event begin play" method to store the singular reference. I wanted to add a noise indication to when you're detected but am unsure how you would go about storing the second reference. Thanks :)
Disregard! Found a way to utilise an audio component attached to the character BP itself! Thanks again for your excellent tutorial i'll be back for more in future :)
@@gallahad2889 please explain how you did so, currently needing a fix
Is nav mesh bounds and nav mesh bounds volume the same thing?
Cool. Could you make a tutorial where you do all this with your own chracter and animations?
Just follow his tutorial on player animations, but do everything for the enemy instead.
Hello! I have problem.. I do every from this tutorial but if the music start, AI isnt move.. Can u help me please? 😅
How would you make him return to his patrol after the chase?
So I followed this close, but for some reason the AI still comes after me even after I'm out of sight and the music has faded. He just doesn't stop walking. How can I fix this so when I'm out of sight, he stops moving?
the audio starts instantly playing, do you know how to fix? and also doesnt stop
My game uses the first person template. How would I get the blueprint for the 3rd person character?
is there a way to make the ai faster while it is chasing the player?
Is 90 degrees the maximum peripheral vision in UE? I would like my AI to have it at 360 but whatever value above 90 I enter, it still counts as 90.
Brother... it's not, I guess. Cause, I've kept it as 120 degree...
Hey i absolutely love this but how would i do this with a custom npc for example with a different skeleton other then the mannequin im trying to make a wendigo game and stuff and a note is that im using mixamo rig for it
Hello Matt. I'm making a first person shooter game and I'm having trouble with figuring out a camera transition for a death sequence. I'm pretty new to Unreal and coding for that matter. So I've been looking around but haven't had any luck figuring this problem out. What I'm trying to do is have the player get stopped by the npc and is forced to turn towards it for a one hit kill animation. I've gotten the inputs to be disabled for my character so the npc can land on top of him, and the camera turns smoothly towards the enemy. What I'm trying figure out is a way to have the camera pan upwards as the npc jumps and lands on him. The problem is that I've used a root animation on top of my animation I made in blender so the camera doesn't track the npc's mesh as is flies towards him. It's like the first person camera refuses to move, and I don't understand how camera manager functions in telling the camera to rotate or translate. Any advice would be much appreciated.
Probably already found a fix, but off-the-cuff idea might be to have it look at the NPC's head socket, or something similar.
now I'm wondering if you were involved with the coding in Metroid Dread ;)
can u make tutorial that when we are normally moving our heartbeat is normal but when we closer to enemy radius the heavy heartbeat plays plsssssssssssss make tutorial on this
pls
Mine is messed up: AI is apparently player, and player cannot spawn in designated "start Spawn" area. Game freezes & unable to get out of it except restart PC.
music plays 2 times almost at the same time, how to make it play only 1 time ?
You always have "lighting needs to be rebuilt" in screen.. you really don't mind do you? 🤣
Hahaha, I don't mind no lol. It's always there when you start a project so I just leave it there lol
No devs wont care that unless the final build in done!
how do you make the ai patrol to random places?
i got an error it says accessed none trying to read property audio
Hi, i watched tutorial but my enemy stands still doesnt move at all, the music plays and fades but the enemy is as still as a statue lol
hey matt i love the tutorial but when the enemy chases me the chase music doesnt start, and when i stop playing i get a bunch of sound errors in error log, do you know why?
this had happened to me and it was because I wasn't putting on a set in the audio. In the event begin play
The first time that enemy chase me, if i´m too close, lets say 5-10 units, it stops chasing me and just return to random walking, even if im running in front of him and very close. If i´m far away it works perfectly. Could you help me to fix it? please!
Hey, I've just tested mine and it appears to work all the time, even really close. So I assume we have some differences in our code somewhere. One thing I'd suggest checking is that if you select "Pawn Sensing" your AI settings are the same as mine, imaged below, and that on your "On See Pawn Event", off of the sequence you are using a "Retriggable Delay" set to 0.6, not a normal delay. Let me know of any updates.
imgur.com/a/SDOu7Ub
I did this and the roam tutorial and it worked great, but after I added your main menus and pause menu the AI just stopped working, it starts the music but the model keeps standing still. I have no idea what to do
SOLVED! I had an eureka moment today on the train. I remembered putting colliders all over the map so that player cannot go over hills on fall off the cliff, and it seems that Nav Mesh Bounds Volume stopped working, so I just deleted it and imported another one, now the chasing npc works again!
That air is frightening
Hi Matt, i have a problem. When i escape from the ai the music stops playing, but he still finds me/ continues to chase me. I've re-watched the tutorial and everything is fine, but i still have the issue. Pls help!
i have the same issue, i really hope he answers this
my ai dont have a movement animation what i do wrong?
I don't understand why the audio doesn't play when my character approaches the enemy.
I followed what you said in the tutorial to the letter, but it doesn't start.
Hi, just going to run through some troubleshooting. Do you have any audio inside of unreal, i.e. do other things also play audio? If so, does your chase audio work when opening it up and previewing it, or does the file not play at all? If you have no audio whatsoever, can you open a new project and see if it still persists, or is the issue only in this one project? Hope these can maybe help push in the right direction :)
Damn it boi, where were you?!
I have tried 4 diffrent tutorials but my enemy still dont want to move
Can u show me how to make this Ai to move random places?
I followed one of your other tutorials on roaming ai blueprints and I am trying to add this blueprint to the same AI but i cant add a new event tick mode, is there a way around this or a different node i could use?
Hey! I found a way to use roam AI with this! You just need to attach the 'Random Float in Range' from the Roam AI to the Delay in this. Then after the 'Fade Out', add a 'Sequence' and attach the 'Then 0' to the 'DoOnce' and the 'Then 1' to the 'SET Is moving?' from the AI roam. Hope this helps!
epic
I'm loving these videos very helpful, I know this is an old one and so maybe its an issue with the updated engine, but I can get the character to chase me, but I could not add the sound effect as it would not let me add another Event to begin play node, it just zooms in on the Begin play node that is in the 3rd person blue print, anyone have any ideas how I can solve this?
Ignore, I've sussed it, you don't need all that top code as its not a playable character
how to make him see the player, if i am right behind him ?
how can i make it kill me when it touches me?
10:00 The music is restarting to play when AI sees character second time. I have the same issue. Any ideas on how to fix that?
I had the same problem until I realized that I set the [Fade Out] link wrong into the [Do Once] I put it in the wrong nod instead of the "RESET" one. Maybe you did the same thing.
Any one know why this doesn’t work when you build the project?
I lik that one
Thank you! :)
Great tutorial! But I'm having a problem. The whole thing was working perfectly until this morning, when my enemy AI randomly began to continue following me, even after I was hidden. I have no idea what could have changed. I checked and double checked the blueprint to make sure nothing is different, but I can't see any changes. Any ideas? The only thing I've done is added a new map and added some new code to the player character. (Nothing big, just a simple flashlight and a sprint input action.)
I've got the same problem. Have you figured it out yet?
@@Tubicaaa Not exactly. For some reason, when I placed the exact same AI characters into a new map, the problem disappeared. No clue what happened in either case, sorry.
is there an animation graphic i can add? like a detector?
that pops up on screen? that would be cool kinda like ghost recon wildlands.
Hey, yeah you could have it so when the chase starts it goes "create widget>add to viewport" with a widget in that create which is what you like, maybe some text. Then when the chase ends, get a reference to this widget and get "Remove from parent". Hope this helps, let me know if you need a hand with it :)
My AI can't seem to lose me? As soon as it sees me, it follows me even if I escape its line of sight?
Ah okay, this could be a number of things, so could you maybe copy and paste your code to this website and send it here again? That way I can take a proper look for you :)
blueprintue.com/
Ahh I thought he was gonna play flight of the bumble bee!
You should do a stealth tutorial (e.x Hiding under a table to avoid AI's detection) :)
Hey, great idea. I did one for hiding in a locker which you might like? All the best to you :)
ua-cam.com/video/gHJ4pHlqAzQ/v-deo.html
@@MattAspland I loved it, but is it possible to not get detected by an AI whilst hiding in it? :)
@@firstgamerable Yeah, when we set the actor to be hidden in game, it shouldn't be able to spot you, this worked for me. Does the AI still see you with that?
@@MattAspland I've actually followed your bed-hiding tutorial. The hiding mechanism did actually worked, but the AI can still see me, weird.
@@firstgamerable Oh that is weird, and your character is definitely set to be hidden in game right?
the script stopped working for no reason, can anyone help?
Great tutorial, but im having an issue, the music plays when I get chased, but then dosent stop when im out of sight... Can I pls have help....
NVM i forgot to connect the flase branch to the fade out... im new to this
Could you make a tutorial for an AI that opens doors. Ty
how to fix it (accessed none trying to read property audio) ?
I have the same problem
Help us please 🙏🥺
the fact is because you havent put any stairs to your level then the enemy doesnt really stops seing you, its because you are not reachable that the ennemy stops following you. In reality, the ennemy stills follows you but because you are not reachable it stops the function. I need to make it stops running to me when there is a wall that hides me
yes that's the trick he used for this tutorial😁😁😁
Great stuff!
I've watched and followed a few methods of enemy detection.
I will no lie Venmo you $40 if you do a behavior tree.
I've seen a few but still get confused
Thank you!
I can definitely look into doing a behaviour tree tutorial yeah, I'll add it to my list thank you :)
i dont know what im doing wrong, But for the main part it works flawlessly! but when the audio fades out and im clearly out of sight, the ai still chases me. Im going to have to figure that out haha
I think, it is because the AIMoveTo function does not stop until it gets to your position or is not able to get there (like you are out of nav mesh). Anyway to fix it, try to call StopActiveMovement function on AI character, when you stop music.
Thank you for the great tutorial!
I have a small issue where the AI still follows me even after it hasn't seen me for over 2 seconds. The music stops too but the AI still chases. When it sees me again the music starts again. Does anyone have an idea why this could be?
Well, I fixed that issue by replacing the ''event tick'' by a custom even called ''Stop Chase''. I then called ''Stop Chase'' after the Retriggerable Delay.
I also added ''Stop Active Movement'' after the Fade out music and called back my patrol event.
That way my AI return to patrol and stop following you everywhere.
@@ztormsink5931 Thank you for your suggestion, I was able to solve the problem. As someone else suggested, the "AI Move To" doesn't stop the action until the target point/object is reached. To stop the action I just used "Stop Active Movement (Target is Nav Movement Component)" and plugged "self" (in the AI Blueprint) into it. I used this before "Fade Out" and it worked! When the AI sees me again, it starts chasing again.
@@Linus_UA-cam I had the same issue and did what you said fixed it, and it worked for me too! I just plugged it in at the end of the *CanSeeEnemy False* Segment of the code, and it worked like a charm!
Bro can u make replicated version pls.
get ref to self does not work :(
My enemy never stops chasing the player
dont lose your time , in new version of UE4 , "self" cant be linked to "AI Move To"
One question how can i change the speed of the enemy?
hi, I'm happy you didn't ask this question long ago cause I just found the answer. You just have to drag the character movement component, get it, then pull a Set Max Walk Speed from it and plug the Set speed in the event begin play. I plugged it before the audio component but I don't think it matters :)
I don't know why, the music part works but it doesn't chase me?
Never mind mate, I've done it, bangin tutorial.
hey, thank you for the tutorial. However, I am having an issue where the music is played over and over for each enemy. For one enemy is works fine, but for multiple enemies, it plays multiple copies of the music also.
You're probably going to have to remove the code for playing the music from the Enemy AI and set up something in the Level BP instead that starts playing the music when the Can See Player Bool switches to true. I'm not 100% sure how to do this so you're probably on your own on that one. Good luck though.
@@xantishayde-walker4593 Thanks, yeah I tried that also haha. I have the code in the level bp, and it's called when the pawn senses the player. I'll figure something out
@@Davey123able hey man not sure if you figured this out but you could try adding a valid check before the music starts, if it's not valid create the music and if it is valid then continue with the code?
@@BearyK8 Hey, I believe I had tried that before, but I have just switched entirely to a different system like most traditional mmorpgs. So when the weapon is drawn, the combat music starts and vice versa. Makes it a lot more easier in my opinion, although not as dynamic
I'm gonna try this, I want the pawn sensing to be like a viewcone. I want to make a stealth game, even though it's just my second day in UE4. Do you think I'll be be able to do it ? :D
Hey, of course. You can do anything you set your mind to, if you put in the work and determination, I'm sure you'll do it! I wish you all the best of luck :)
@@MattAspland Thanks!
@@GoofyRiderFilms No problem, good luck and I'm always here to help :)