The Daily Click ::. Forums ::. Klik Coding Help ::. Following/companion AI
 

Post Reply  Post Oekaki 
 

Posted By Message

vetmora120



Registered
  07/01/2010
Points
  273
30th June, 2010 at 06:27:55 -

I uploaded the engine of my game DRAX on here in the downloads section a while ago and people suggested I make the AI of the companion smarter. So, I have been trying for about a month now to get the AI on the companion to work well but I can't seem to find much on these sorts of AI's.

I've tried a method that when the player does an action it drops an object with that action stored and when the companion/follower hits that object it copies the stored action. This was a good method but I couldn't seem to get it to copy the player exactly.

Another method, which is the best I've found by Retriever II, uses the Lua object. It basically always stores the players x, y and any other variables you want and when the list reaches the desired number it applies it to the follower, getting the exact path the player takes. The problems with this method is that it's not very flexible (not that I know anyway) in that I can't find a way for the follower to stop a distance away from the player rather than always trying to stand exactly on the same x and y. Another problem is that because the player can glide, and the follower shouldn't be able to, it does anyway because it always copies the coordinates. The same applies to the jumping on back action of the player.

If anyone has a method to achieve a smart follow AI for a platformer then it will be greatly appreciated if you list it here or supply an example or something. Thanks in advance.

 
n/a

Silveraura

God's God

Registered
  08/08/2002
Points
  6747

Game of the Week WinnerKlikCast StarAlien In Training!VIP Member360 OwnerWii OwnerSonic SpeedThe Cake is a LieComputerChristmas Tree!
I am an April Fool
30th June, 2010 at 07:21:06 -

What you could try to do is really just make the character aware of it's surroundings.

Give it a variety of sensors that detect a variety of stuff, for example a right sensor that collaborates with a ground sensor to tell the companion to jump if the player is in that direction and he's running toward him. Set up a set of qualifications which you think might not be entirely necessary too. You can never plan for every possibility that might happen but you can try your best to think of as many as you can.
For example, in Sonic 2 and 3. If Tails gets far enough away from you that he can't catch up but close enough that he doesn't respawn, he will stop and do a quick spin dash in your direction to get him there faster. It wasn't 'cheating' in that the computer moved him, he used a legit player move to get himself closer to you.

Think logically about what your player has to do to do what you just did. I mean, what made you do it in the first place? Did you see an enemy within a distance you knew you could attack from? Maybe your companion could have a distance calculator and a set of specific conditions which provoke an attack?

Then theres always the whole, mimic the player movement. This will most likely take over the majority of the engine, but that does not mean by any stretch of the imagination that it's the most important part. The goal is to make your player smart enough to hold his own, and this is more or less just the skin of his movement so as to make his job easier.
One upon many methods I can think of that might work pretty well for this is to use string parser in the same way you might make an identical entity of yourself copy your moves in an online game.
Make it so that anytime you do something, you add a specific string to a list box or something. For example, if you jump, the string would be "jump" or if you press right "press_right" or "released_right" and so on. You can also create a counter which always adds 1 and use this as a reference of time for when a move is done. Tack it onto the end of the move, for example "press_right,1500" using "," as a delimiter. This is where string parser comes in because the time would be element 2.
Then create another group where in which the companion will go down the list and perform each move at the specified time, but match that time with another counter which is so many sections behind the original counter. This way the companion will duplicate the moves at the time the player did them, plus whatever the counter is behind. Set it however far you want.

You should also set up some sort of safety net though so that if the companion leaves a specific distance or something occurs that would make your moves irrelevant to what he needs to do to get back to you, shut off the group which he duplicates your moves in and keep emptying out the list. Then let his sensory override take over so that he can accomplish whatever he needs to to get back to you so that you can reactivate the copying group.

 
http://www.facebook.com/truediamondgame

vetmora120



Registered
  07/01/2010
Points
  273
30th June, 2010 at 08:28:37 -

I like the string parser idea, thought it's gonna take a while to get my head around it and create a fully functional engine for it. I've used the object a few times in the past but never thought of putting it to use for this sort of thing. Thanks for the suggestions and I look forward to others input.

 
n/a
   

Post Reply



 



Advertisement

Worth A Click