- Home /
The question is answered, right answer was accepted
Creating an Enemy Jet AI
Hello, I have a question.
I tried to look for resources and information over the internet, and I couldn't find anything useful.
The issue is, that I don't know how to implement my thoughts, I mean, the AI will have a switch case which, he could:
Seek/Scan/Normal : The normal state, the jet is flying around.
Chase and Shoot: The AI is triggered and trying to kill the player.
Flee : The AI will try to shake off the player jet.
I'm trying to think of which of the Unity3D tools I can use to execute my thoughts. The Lerp or Slerp would make a "Un-real" movement if suddenly the enemy jet would turn without physics movement...
Do you have any ideas?
Check out the AI tutorials on unitygems.com, you will even find a finite state machine framework specifically to deal with states nicely.
Thanks, however, I didn't see anything related to the jet AI, do you think you can give me a more specific link?
Answer by Meater6 · Feb 10, 2013 at 09:52 AM
If you look in the standard assets, there's a script called a character motor. It basically does all the movement, without any AI or input whatsoever. This is what you need for your jet.
Of course, your jets are not bipedal creatures. You will have to make a custom one specifically for an aircraft. This will give the player and the AIs realistic (or at least similar, depending on how well you write it) movement. Then you can make a separate script that deals with the player's input and the enemy AI.
I hope this helps! :)
Thank you for you answer, but I don't think you understood me correctly. I went through the Character $$anonymous$$otor script, and I didn't find anything useful.
I already created the necessary physics movement for the player, I could also use these for the AI jet, however, and this is my problem, No one is controling the AI, I somehow have to make the AI learn by itself how to use his physics to chase or flee.
I still highly suggest using a "Jet$$anonymous$$otor" script, (created by you of course). Its not necessary, but I think it will make the issue much easier.
Well, I'm assu$$anonymous$$g you know how to do the state machine and the conditions the each state possess.
When the plane is idle: At the start of the game make its target direction in the direction of the way its facing. Then smoothly shift the direction to the left/right. This will give you the basic circling movement.
Chasing/Fleeing: You can use the position the player's jet as the reference point of your AI when chasing and fleeing. When chasing, simply make the target direction the direction of the player. When fleeing, make it the opposite direction of the player.
Thanks again, So you're saying that I should create a script for a certain target (which is a position, (Vector3)) and just work on a script how the AI will go there. Well, first it does make everything easier to think that way, in a "way points" pattern, then I could make way points for the AI being idle and all the other states.
However, the real question is, how do I implement it with the jet physics? I mean, the player could be in so many positions, and for each position I'll need to create a waypoint for it?
Calculate the direction the player is in:
targetDirection = playerPos - tr.position;
targetDirection = Vector3.Normalized(targetDirection);
That's it. The jet will always follow the character.
But you should tell us what you've tried so far, where you are with this... you're expecting people to magically know what you want.. why don't you write the whole thing with that "slerp/lerp" approach and see how it goes... I don't see why that would be "unreal". You can also use SmoothDamp, which is an even more smooth and dynamic function... it doesn't matter if your character is above/left/whatever to the enemy... it can just damp to the desired direction smoothly... I don't see why that would be unrealistic... Well, you can even throw in some randomness in the enemy movement, but that you should do only if a basic follow script is already working....
Follow this Question
Related Questions
Artificial Intelligence 1 Answer
BDI Agent Programming in Unity3D 1 Answer
need a logical tip for AI 2 Answers
My model from Blender does not follow the AI script properly! 2 Answers
Tutorials for AngryAnt's Behave 1 Answer