AIPlayer::setMoveDestination
by Brian · in Torque Game Engine · 03/24/2008 (11:52 pm) · 8 replies
This is probably a simple to answer question but I've been searching blindly and can't find anything to really explain it to me. I'm using Torque Game Engine (TGE) 1.5.2 stock and working off the FPS starter.
Let's say I just wanted to spawn a bot and have it move 5 units straight ahead of him no matter where he is facing. How would I go about, in either script or code, being able to drop a bot onto the terrain and just set his target 5 units ahead of his current position no matter what rotation he is at? I don't need to know how to actually spawn a bot, just how you would take his current position and get the position 5 units straight ahead of him.
Let's say I just wanted to spawn a bot and have it move 5 units straight ahead of him no matter where he is facing. How would I go about, in either script or code, being able to drop a bot onto the terrain and just set his target 5 units ahead of his current position no matter what rotation he is at? I don't need to know how to actually spawn a bot, just how you would take his current position and get the position 5 units straight ahead of him.
#2
03/25/2008 (9:56 am)
Thanks for the help Gary! Do you have any recommended resources for working with vectors (doesn't necessarily have to be Torque specific)? I'll read up on these gamedev.net resources as well but am willing to take suggestions.
#3
I can recommend a book though, "Beginning Math and Physics for Game Developers" covers quite a lot of the basics. There's plenty of books that go into more detail, but for the complete basics, I think that book covered it quite well.
03/25/2008 (11:43 am)
There's probably a load of on-line resources to do with vector math but I can't think of any off hand.I can recommend a book though, "Beginning Math and Physics for Game Developers" covers quite a lot of the basics. There's plenty of books that go into more detail, but for the complete basics, I think that book covered it quite well.
#4
03/25/2008 (2:04 pm)
Sweet, I'll give that a read. The company I work for provides me with safari e-book access and they have that particular book. I'll check it out when I get home. Thanks for your time Gary.
#5
%bot.setAimLocation(%newPos);
Unless he wants the enemy to be aiming at the player I guess.
Vector math = *ugh*
:)
One quick follow-up question if I may, Gary - I've used the code you posted many times in my game to move the character forward or back relative to his currect position, but the math that I can't seem to figure out is if you wanted the character to move say 5 units to the left or to the right.
03/27/2008 (6:13 am)
Correct me if I'm wrong but wouldn't he also want to put...%bot.setAimLocation(%newPos);
Unless he wants the enemy to be aiming at the player I guess.
Vector math = *ugh*
:)
One quick follow-up question if I may, Gary - I've used the code you posted many times in my game to move the character forward or back relative to his currect position, but the math that I can't seem to figure out is if you wanted the character to move say 5 units to the left or to the right.
#6
A clarification will probably be needed David. Do you mean to strafe left or right or to turn the character left or right (rotation)? I can't really answer it either way but I figure if Gary has time to answer, he'll probably want to know that.
03/27/2008 (10:33 am)
Quote: One quick follow-up question if I may, Gary - I've used the code you posted many times in my game to move the character forward or back relative to his currect position, but the math that I can't seem to figure out is if you wanted the character to move say 5 units to the left or to the right.
A clarification will probably be needed David. Do you mean to strafe left or right or to turn the character left or right (rotation)? I can't really answer it either way but I figure if Gary has time to answer, he'll probably want to know that.
#7
Here's an example for you
Not the best code in the world, but should get you on the right track.
03/27/2008 (11:03 am)
Moving to the left or right is a similar process to moving forward, only rather than basing it on the "forwardVector" you want a "leftVector" which you can obtain with a little more math. Using the cross product of the forward and the "up" vector will give you a vector at 90deg to it. Here's an example for you
//-----------------------------------------------------------------------------
// Returns position relative to players forward vector
function getRelativePosition(%bot, %dir, %dist)
{
%pos = %bot.getPosition();
if (%dir $= "left" || %dir $= "right")
%vec = VectorCross( "0 0 1", %bot.getForwardVector() );
else
%vec = %bot.getForwardVector();
if (%dir $= "behind" || %dir $= "left")
%vec = VectorScale(%vec, -1);
%pos = VectorAdd(%pos, VectorScale(%vec, %dist));
return %pos;
}Not the best code in the world, but should get you on the right track.
#8
wrestler1.setTransform(getRelativePosition(wrestler1, "right", 1.5));
If so, that's phenominal - thank you tons
03/27/2008 (12:13 pm)
I'll go home tonight and try this, but I believe that's exactly what I need. Basically I'm creating a wrestling game and for a few moves here and there, I need to tweak the position of the wrestler forward/back/left/right so he's in the correct position for the move. So I believe after it's all said and done, to nudge the wrestler one way or the other, I would say (assuming the id is "wrestler1", the direction is left and the amount is 1.5):wrestler1.setTransform(getRelativePosition(wrestler1, "right", 1.5));
If so, that's phenominal - thank you tons
Torque Owner Gary Preston
What this does is get the forward vector, which is a vector pointing in the direction the bot is facing. It then gives this vector a length of 5 units by normalizing and scaling. That gives you a vector that will move the bot 5 units forward. Add this to the bots current position, and the result is the final destination.
I'd recommend learning about Vector Math, it's very useful for many situations in game programming.