Cover shooter mechanics implementation
Closed this issue · 9 comments
This isn't a bug or problem with the library, I'm just curious about how a specific situation might be implemented. I figured this would be the best place to ask for now.
I want my enemies to take cover from time to time, and shoot out of it. I figure my the goal would be minimizing the player's health, but I'm not sure how to make sure the enemy will consider their own safety. Maybe the goal would also maximize the enemy's safety, but I don't think that would work out. Should I try and bake in danger as part of an action's cost and rely on the agent re-planning? Any advice here would be helpful, thank you,
So one "correct" way to do this would be to have two separate goals, with appropriate weights. One would be "reduce player health" and the other would be "maximize own health." You could then easily adjust enemy behavior insofar as how aggressive they are by changing the weighting on each goal.
But really, adjusting cost based on a danger factor isn't wrong either. That's probably not how I would do it, but it's a valid approach! "Cost" is a very generic term here for exactly that reason -- it can represent many things, depending on the usage scenario.
I tend to start from mentally modeling the agent's goals and then working out how to get to the goals from there in terms of actions they could take, etc.
Is that helpful? Happy to provide slightly more detailed examples, but exact implementation will really be dependent on your game's specific code.
Yeah, I guess I want the enemies to actively consider their safety while they are attacking instead of switching from attack mode to safe mode. I'll definitely try out both, but I guess there is no way to really see until I actually implement this into my AI. Thanks
Ah, in that case using a cost callback for aggressive actions that takes into account danger factor is probably a smart approach. That way the weighting of the "attack" goal would effectively decrease as there was more danger.
EDIT: you could also introduce a third goal (be safe while attacking) that requires everything the other two goals require. Actions that optimize for neither safety nor aggressiveness might be chosen for that third goal since it will help with both factors, depending on how everything is weighted and built.
Thanks, I will try this.
I'm also a little confused about how state works. If an action succeeded, is the postcondition set as the new state, or is it the responsibility of the executor to make that happen? In my case, I don't want to store the HP value inside the agent state, so I would probably lean toward using sensors for pretty much all of my values. Am I thinking about this the wrong way? Thank you.
Postcondition will be set automatically if the action executor returns a successful value. I would recommend having a sensor that sets the HP value inside the state to whatever value you have it at outside of the state (assuming you need the HP value for determining which action plan to use). Then you can set it as a postcondition without worrying about it affecting the real HP value.
Great. Thank you for the advice, I'll close this issue.
Sorry about that, I just noticed something. If I want my AI to consider what is actively happening, is it safe to add and remove actions whenever?
@UhGoomba, I would probably check agent.isPlanning
and treat the actions list as locked whenever it's set to true
. Probably not the safest to modify while planning.