Making my bot move more intelligently.
by Jason Gossiaux · in Torque Game Engine · 04/01/2008 (10:26 pm) · 16 replies
Could anyone help direct me in learning how to make bots take a few steps backwards? I've not seen this explained anywhere, and can't seem to figure out how the source code would handle it. As a player you set $mvBackwardAction but I never see that variable used anywhere.
I guess my other question is how can you add an impulse that is a constant? My AI Think function only runs once every 500ms, and the impulses are quite visible at that scale. I am hesitant to run it more often, or add a faster impulse scheduler because I think it would still be visible and could use up a lot of resources when handling many bots. Is this something I'll need to modify the source to do?
Thanks for any help you can give me with this! I'd searched the forums and checked out KillerKork and didn't see anything like this described inside.
I guess my other question is how can you add an impulse that is a constant? My AI Think function only runs once every 500ms, and the impulses are quite visible at that scale. I am hesitant to run it more often, or add a faster impulse scheduler because I think it would still be visible and could use up a lot of resources when handling many bots. Is this something I'll need to modify the source to do?
Thanks for any help you can give me with this! I'd searched the forums and checked out KillerKork and didn't see anything like this described inside.
About the author
#2
04/02/2008 (7:00 am)
Hehe, darn. I thought that is what was going on :P Nah I know my C++, but for this first build I was trying to get away with as much in TScript as possible. Thanks for shedding more light on things for me!
#3
04/02/2008 (12:56 pm)
So I guess this just leaves my other question about constant impulses. What would be a good way to simulate a strong wind pushing against someone? Is hacking up the source my only recourse?
#4
04/02/2008 (2:57 pm)
Read up about physical zone's, they could achieve that effect.
#5
04/02/2008 (6:34 pm)
Hmm, so if I can manage to get them walking backwards how might I also get them to play the "walk backwards" animation while they are doing it?
#6
Generally speaking, anything that causes them to move by internally, by some method, modifying Gamebase::mVelocity, it will also cause them to change their action animation appropriate for that velocity.
Its possible a physical zone does not modify mVelocity ( maybe it directly modifies the position ). I don't really know without looking at the source code.
04/02/2008 (9:46 pm)
Are you having a problem with them not playing an animation?Generally speaking, anything that causes them to move by internally, by some method, modifying Gamebase::mVelocity, it will also cause them to change their action animation appropriate for that velocity.
Its possible a physical zone does not modify mVelocity ( maybe it directly modifies the position ). I don't really know without looking at the source code.
#7
04/02/2008 (10:25 pm)
I'm not really sure how to describe what is happening. I adjusted the yaw calculation to be the reverse of what it is normally in an attempt to just get all my bots walking backwards from spot to spot. Except they keep flip flopping while walking. They turn backwards, then forwards, and so on really really quickly until they reach the destination which I find odd. I only see the one place in GetAIMove() where the Yaw is being handled.
#8
I made a game for my wife a while back simulating freeze tag. The Bots needed to run away from the "it" guy instead of always running at him. Similair to "taking a step back" except I would have them turn and run.
We can achieve what you are after by setting an aim object and setting a move destination (all in script). If you are taking a step back from a target (which from the title that's what it sounds like) you can set that as your aim target. If you want to move away from the target a certain distance, then all you need to do is some vector math to find a position behind itself.
Something along the lines of:
So, with an aim object it will continue looking at the target, and move to its destination. So, it will walk backwards.
You could replace setAimObject() with setAimLocation() and you will get the same effect. In case you don't have a target.
Hope I understood correctly. If you have more then 10 bots in script running around you probably don't want to make them think much faster then 1000ms. Even with just pathfinding this can cause slow downs.
Maybe you can give more insight on why 500ms is not fast enough?
04/02/2008 (11:40 pm)
I'm going to address the first question in a different way. James' answer is good, but I always love to give a different approach option to people learning.I made a game for my wife a while back simulating freeze tag. The Bots needed to run away from the "it" guy instead of always running at him. Similair to "taking a step back" except I would have them turn and run.
We can achieve what you are after by setting an aim object and setting a move destination (all in script). If you are taking a step back from a target (which from the title that's what it sounds like) you can set that as your aim target. If you want to move away from the target a certain distance, then all you need to do is some vector math to find a position behind itself.
Something along the lines of:
// set the bots aim object %bot.setAimObject(%target); // get both positions %position = %bot.getPosition(); %targetPos = %target.getPosition(); // vector distance between points %newVec = VectorSub(%targetPos,%position); // normlize %normVec = VectorNormalize(%newVec); // actual distance between bot and target (engine does sqrt(vec1^2 + vec2^2)) %dist = VectorDist(%targetPos, %position); // using the dist we scale the normalized vector + 2 (arbitrary number i threw in) %newVec = VectorScale(%normVec,%dist+2); // subtract the original vector from the new one. We have a position behind us %newPos = VectorSub(%position,%newVec); // set the bots move destination a few steps back %bot.setMoveDestination(%newPos);
So, with an aim object it will continue looking at the target, and move to its destination. So, it will walk backwards.
You could replace setAimObject() with setAimLocation() and you will get the same effect. In case you don't have a target.
%bot.setAimLocation(%bot.getPosition()); // do move code
Hope I understood correctly. If you have more then 10 bots in script running around you probably don't want to make them think much faster then 1000ms. Even with just pathfinding this can cause slow downs.
Maybe you can give more insight on why 500ms is not fast enough?
#9
I totally forgot about setAimLocation ( It was one of the first things I removed since my project handles head/body targets differently ).
04/02/2008 (11:56 pm)
Definitely try Williams suggestion. I totally forgot about setAimLocation ( It was one of the first things I removed since my project handles head/body targets differently ).
#10
Changing:
04/03/2008 (6:24 am)
Quote:I adjusted the yaw calculation to be the reverse of what it is normally in an attempt to just get all my bots walking backwards from spot to spot.I'm not sure what code you changed, but there's a small "else if" code block that handles facing directions in running.
Changing:
// Update the aim position if we're aiming for an object
if (mAimObject)
mAimLocation = mAimObject->getPosition() + mAimOffset;
else
if (!mAimLocationSet)
mAimLocation = mMoveDestination;to:// Update the aim position if we're aiming for an object
if (mAimObject)
mAimLocation = mAimObject->getPosition() + mAimOffset;
//else
//if (!mAimLocationSet)
//mAimLocation = mMoveDestination;Would keep the bots from facing the direction there running. Sure commenting out the code is a bit permanent, but it should be easy enough to add another bool argument to "setMoveDestination".
#11
04/03/2008 (6:55 am)
Wow, thank you for all the wonderful responses. I don't think I'll have any problems figuring it out now. I'm actually suprised there wasn't more resources for something like this as I'd have expected it to have been somewhat commonplace. I guess this means I'm tasked with creating one :P
#12
Heres an interesting thread / discussion / borderline-flame-war about the level of AI Torque should "ship" with:
www.garagegames.com/mg/forums/result.thread.php?qt=73413
04/03/2008 (9:22 am)
Yep, but look at making your own AI as a fun challenge '-)Heres an interesting thread / discussion / borderline-flame-war about the level of AI Torque should "ship" with:
www.garagegames.com/mg/forums/result.thread.php?qt=73413
#13
I spent about a month writing my pathfinding alone. I built it to use many different algorithms to find the shortest path, the most realistic path, etc etc. The bots will use group pathing, playing follow the leader. I have a multitiered graphing system that allows complex pathing and simplistic pathing. It uses a type of "fog of war" to prevent the Ai from knowing all right away, or you can toggle it off for certain Ai.
Granted I am not a professional programmer, I do this as a hobby. But that's the story for most of us. My pathing was built with reusability in mind, but still does not tackle every possible Ai needs for pathing. I spent lots and lots of time on it, but can still think of scenerios that my system can not fullfill.
Resources for Ai are difficult to share, as most of the time, the application you created your Ai for is unique. KillerKork and the others for example, really only serve one purpose. I couldn't easily turn those into RPG based Ai, or Racing Ai. I would have to re-write most of them.
When submitting Ai resources, I would submit simple sub-systems to Ai (even pathing would be to high level imo). Instead of a wholistic type of Ai.
Just a thought. As James mentions, be sure to have fun. :)
04/03/2008 (4:00 pm)
There is so much that is involed with Ai that it is difficult to say "I've created Ai, here's a resource that everyone can use" since not very many people will actually use the resource in production.I spent about a month writing my pathfinding alone. I built it to use many different algorithms to find the shortest path, the most realistic path, etc etc. The bots will use group pathing, playing follow the leader. I have a multitiered graphing system that allows complex pathing and simplistic pathing. It uses a type of "fog of war" to prevent the Ai from knowing all right away, or you can toggle it off for certain Ai.
Granted I am not a professional programmer, I do this as a hobby. But that's the story for most of us. My pathing was built with reusability in mind, but still does not tackle every possible Ai needs for pathing. I spent lots and lots of time on it, but can still think of scenerios that my system can not fullfill.
Resources for Ai are difficult to share, as most of the time, the application you created your Ai for is unique. KillerKork and the others for example, really only serve one purpose. I couldn't easily turn those into RPG based Ai, or Racing Ai. I would have to re-write most of them.
When submitting Ai resources, I would submit simple sub-systems to Ai (even pathing would be to high level imo). Instead of a wholistic type of Ai.
Just a thought. As James mentions, be sure to have fun. :)
#14
Currently I have a decent 4-million node generated at runtime A* pathfinding going on. I've yet to develop a good method for handling interior pathfinding. That will take some thinking. Path steering and obstacle avoidance while chasing people and walking from node to node is where being able to step backwards and to the side seems like it would come in handy.
If anything I'd just release a new AIPlayer function that has passed arguments for walking backwards and to the side. Nice and simple like.
04/03/2008 (8:07 pm)
Well don't get me wrong. I don't support having GG spend resources on improving the shipping AI. But I just thought walking backwards/sideways would have been a no brainer - at least from the community :PCurrently I have a decent 4-million node generated at runtime A* pathfinding going on. I've yet to develop a good method for handling interior pathfinding. That will take some thinking. Path steering and obstacle avoidance while chasing people and walking from node to node is where being able to step backwards and to the side seems like it would come in handy.
If anything I'd just release a new AIPlayer function that has passed arguments for walking backwards and to the side. Nice and simple like.
#15
I thought I had a lot of nodes ( ~100k ) and I had to implement saving/loading because it was horribly slow. Then again I'm doing a raycast and a sphere test for every node.
Also the nodes have to allocated individually because we throw out the "invalid" ones, and all this requires looking through every node multiple times.
Out of curiosity, are you using immersiveAI as a starting point for your A*?
By the way, this is exactly the stuff I've been working on in our project for the last month ( minus interiors - we don't have any ). So drop me a line if you feel like it.
04/03/2008 (10:39 pm)
Thats a ton of nodes... at runtime... ? I thought I had a lot of nodes ( ~100k ) and I had to implement saving/loading because it was horribly slow. Then again I'm doing a raycast and a sphere test for every node.
Also the nodes have to allocated individually because we throw out the "invalid" ones, and all this requires looking through every node multiple times.
Out of curiosity, are you using immersiveAI as a starting point for your A*?
By the way, this is exactly the stuff I've been working on in our project for the last month ( minus interiors - we don't have any ). So drop me a line if you feel like it.
#16
@William: You have a good point. Often a simple AI system is more useful to more people than a complete one. For example, I've been working for a while on an system that uses a genetic algorithm to create neural nets, which use variations on a* to attack in different ways. It works great. But when I submitted the resource, I only included the a* part, because that is the only part that other people would find remotely useful. The rest is too game-specific for anyone to use.
04/22/2008 (2:22 pm)
It doesn't take a rocket scientist to make the bot walk backwards. Just set it to aim at a location opposite form the direction it's walking.@William: You have a good point. Often a simple AI system is more useful to more people than a complete one. For example, I've been working for a while on an system that uses a genetic algorithm to create neural nets, which use variations on a* to attack in different ways. It works great. But when I submitted the resource, I only included the a* part, because that is the only part that other people would find remotely useful. The rest is too game-specific for anyone to use.
Associate James Ford
Sickhead Games
AIPlayer does calculations and generates a Move in ::getMove, which uses the position set in ::setMoveDestination. I would probably pass an additional parameter to setMoveDestination for "isReverse", and a new bool to AIPlayer mIsReverse. And then can use that bool as flag in getMove to generate the move->yaw differently.
The actual amount of code change to AIPlayer would be quite small to get this working, but if you are completely new to the C++ side of the engine or haven't looked at the AIPlayer class before, its going to take a while to see how the heck it is working.