I have a bit of a hefty question, I’m not very good when it comes to AI so this has been stumping me. I have a floating character that follows the main character kind of like Aku Aku from Crash Bandicoot or Sparx from Spyro the Dragon. What I want him to be able to do is to fly with my character and “decide” which side he wants to be on given walls and just whether he wants to be on that side for some reason. When the main character idles, i want him to fly around him and if the main character is idling too long,the companion will start walking on the ground until the main character starts moving again.
Thanks to anyone who can help!
I understand what you want the companion to do, but what is your question?
What do you need to know in order to be able to make him do that?
There’s a lot of ways you could do it, so which way are you trying to do that you’re stuck on or is not working?
AI is all about how you build the “thought process” logic. That is all AI is. Trying to fake “thoughts/decisions” with code. So you have like 2-3 things I can see just from this brief question.
- Choose a side to fly on (really the only AI in your question)
- Orbit the player during idle movement
- Stop orbiting and walk if idle for too long
So for the actual AI part, you would have to decide for your character “what” is he going to decide flight location based on? You mentioned walls…ok so do you want him to seek out walls? Avoid walls etc? I will assume, you want him flying far from walls, so the logic would be something like, run a continuous line trace in an 80 degree arc around the forward vector of the character, if it hits the wall on one side but not the other side set location to hover over the side away from the wall. If later it hits a wall on that side, switch sides. This is how you script AI.
The other 2 issues are a simple branch/boolean set-up not really “AI” as there is no real “decision” to be made for the AI. So you could just get player velocity, if 0 then set AI velocity to 0 and play animation to orbit, or set AI in orbit around the location of the player. If this lasts longer than X seconds set AI to “walk animation”. That is the basics of what you would need to code.