- Home /
AI behaviour in 3D game, general help needed
I'm more of a designer, coding is not really my thing but I have to get through it.
So I need some general help with AI movement and how it interacts with the player.
Things I need 1.AI is supposed to detect player by 'sound' 2.AI is supposed to go to the place where 'sound' was made 3.AI is supposed to roam an area searching for player unless he has heard a 'sound', if thats the case read point 2.
Thats the basics. So how do I go about doing those things ?
I guess I will have to use some colliders, raycasters etc. but how exactly do I combine all this ?
Thnx in advance
Fellow Gamer
Answer by tanoshimi · Jun 19, 2017 at 07:22 PM
This kind of general design question is really suited for Unity Answers, which is intended more for specific technical questions, but I'll at least give you some pointers of what you'll need:
A Finite State Machine, to handle the various states in which the AI can be (idle, alerted, searching for player, found player) etc.
Some sort of sound detection mechanism which will act as a trigger to change states. You can make a trivial approximation by just measuring the straight line distance from the sound source to the AI - if it's less than a certain threshold then it's audible, else it's not. In practice, you could make this much more complicated - different surfaces make different qualities of sound, volume rolloff is not linear, etc.
For roaming, you might want some sort of Autonomous Steering Behaviour.
To plot a route to get to the source of a sound, you'll want some sort of NavMeshAgent
None of these elements are particularly complicated, but you'll need to do some research as to how to best implement them - I'd start by doing a search for the terms I highlighted - there are plenty of examples of all of them already on the 'net.
Answer by JxWolfe · Jun 19, 2017 at 06:39 PM
I don't know how to detect sound, however if you use navigation doc here, then you could set a target vector3 where the sound was and it will go there, then you would have to have a search area and set random targets in that search area until you find the player, then set the target to the player and it would follow the player, when close enough then you can invoke an attack function.
Your answer
Follow this Question
Related Questions
How can I draw a ray for direction object is moving? 1 Answer
how to stop something from following in the y axis 1 Answer
Determining rotation for collision avoidance? 3 Answers
My Player is crossing the ground through air 1 Answer
How to make "enemy" have a frustum(cone) view and not a circle radius 2 Answers