Rotate Vector
by Richard_H · in Torque Game Engine · 09/20/2006 (3:59 am) · 2 replies
Hi,
I'm trying to multiply a vector 90 degrees around the Z-axis.
Reason:
For my game I have an aiplayer and he already chases and shoots at me, but I would like to add strafing motion to his movement.
Code I Already Have:
function AIPlayer::moveDistFromPoint(%this, %point, %dist)
{
%distDif = VectorLen(VectorSub(%this.getPosition(),%point)) - %dist;
%botMoveVector = VectorScale(VectorNormalize(VectorSub(%point,%this.getPosition())), %distDif);
%botPos = %this.getPosition();
%botDestination = VectorAdd(%botPos,%botMoveVector);
%this.setMoveSpeed(1);
if( (%botPos.x >= %botDesination.x && %botDesination.x >= %point.x) || (%botPos.x <= %botDesination.x && %botDesination.x <= %point.x) )
{
if( (%botPos.y >= %botDesination.y && %botDesination.y >= %point.y) || (%botPos.y <= %botDesination.y && %botDesination.x <= %point.y) )
{
if( (%botPos.z >= %botDesination.z && %botDesination.z >= %point.z) || (%botPos.z <= %botDesination.z && %botDesination.z <= %point.z) )
{
%this.setMoveSpeed(0.7);
}
}
}
%this.setMoveDestination(%botDestination);
}
The bot periodicly calls this to move a specified distace (%dist) from the target (%point). I would like to rotate the his move vector by about 90 degrees (maybe less) multiply that by a random number (-5 to 5) and add that to his destination.
Does anyone know how to do this? (I'm just taking Honors Geometry so try to avoid going over my head (if possible) )
I'm trying to multiply a vector 90 degrees around the Z-axis.
Reason:
For my game I have an aiplayer and he already chases and shoots at me, but I would like to add strafing motion to his movement.
Code I Already Have:
function AIPlayer::moveDistFromPoint(%this, %point, %dist)
{
%distDif = VectorLen(VectorSub(%this.getPosition(),%point)) - %dist;
%botMoveVector = VectorScale(VectorNormalize(VectorSub(%point,%this.getPosition())), %distDif);
%botPos = %this.getPosition();
%botDestination = VectorAdd(%botPos,%botMoveVector);
%this.setMoveSpeed(1);
if( (%botPos.x >= %botDesination.x && %botDesination.x >= %point.x) || (%botPos.x <= %botDesination.x && %botDesination.x <= %point.x) )
{
if( (%botPos.y >= %botDesination.y && %botDesination.y >= %point.y) || (%botPos.y <= %botDesination.y && %botDesination.x <= %point.y) )
{
if( (%botPos.z >= %botDesination.z && %botDesination.z >= %point.z) || (%botPos.z <= %botDesination.z && %botDesination.z <= %point.z) )
{
%this.setMoveSpeed(0.7);
}
}
}
%this.setMoveDestination(%botDestination);
}
The bot periodicly calls this to move a specified distace (%dist) from the target (%point). I would like to rotate the his move vector by about 90 degrees (maybe less) multiply that by a random number (-5 to 5) and add that to his destination.
Does anyone know how to do this? (I'm just taking Honors Geometry so try to avoid going over my head (if possible) )
About the author
#2
The dodge() and getVectorFromTransform() code in this thread might be of interest to you.
09/20/2006 (7:27 am)
Richard:The dodge() and getVectorFromTransform() code in this thread might be of interest to you.
Torque Owner Richard_H
www.garagegames.com/mg/forums/result.thread.php?qt=33277