(SOLVED) Need help with rotating vectors in an old version of Torque
by Your Buddy Bill · in Torque 3D Beginner · 04/25/2015 (7:46 pm) · 3 replies
EDIT: I got it working, disregard this thread.
So I'm creating a mod for a game based on a somewhat dated version of Torque 3D (or at least I assume it's Torque 3D, the game is 3D).
One of the weapons in this mod is a "Wave Shot", which fires a single projectile where the crosshair is pointed (from the weapon's muzzle vector). In addition to that, it fires four more projectiles. Ideally, I want these five projectiles to form a + shape on the screen of the player who fired them; in other words, the vectors for the four additional projectiles should be rotated ten degrees from the muzzle vector in the directions right, left, up, and down, relative to the muzzle vector.
I have no bloody clue how to do this. I've gotten help from folks on the coding help forum of the game in question, but they haven't figured it out either.
How do I create a vector that is rotated relevant to the muzzle vector?
Here's the code so far. Sorry, I don't know how to mark anything up here.
I don't know how to calculate %vecrot1 through %vecrot4, hence this thread.
function vwaveImage::onFire(%this,%obj,%slot)
{
%projectile = vwaveProjectile;
%obj.playThread(2, shiftLeft);
//%obj.toolAmmo[%obj.currTool]--;
//%obj.AmmoSpent[%obj.currTool]++;
commandToClient(%obj.client,'bottomPrint',"<just:right><font:impact:24><color:fff000>Wave Shot<font:impact:34>c6" @ %obj.toolAmmo[%obj.currTool] @ " / " @ %obj.client.quantity["Vwaveshots"] @ "", 4, 2, 3, 4);
%vector = %obj.getMuzzleVector(%slot);
echo("vector is " @ %vector);
%vector1 = VectorScale(%vector, %projectile.muzzleVelocity);
echo("vector1 is " @ %vector1);
%objectVelocity = %obj.getVelocity();
%vector2 = VectorScale(%objectVelocity, %projectile.velInheritFactor);
echo("vector2 is " @ %vector2);
%vecrot0 = %vector1;
%vecrot1 =
%vecrot2 =
%vecrot3 =
%vecrot4 =
//NEED HELP HERE
echo("Vecrot0 is " @ %vecrot0);
echo("Vecrot1 is " @ %vecrot1);
echo("Vecrot2 is " @ %vecrot2);
echo("Vecrot3 is " @ %vecrot3);
echo("Vecrot4 is " @ %vecrot4);
for(%shell=0; %shell<5; %shell++)
{
%p = new (%this.projectileType)()
{
dataBlock = %projectile;
initialVelocity = %vecrot[%shell];
initialPosition = %obj.getMuzzlePoint(%slot);
sourceObject = %obj;
sourceSlot = %slot;
client = %obj.client;
};
MissionCleanup.add(%p);
}
return %p;
}
Please send help, I've been at this for a week with no progress.
EDIT: I'm not actually sure whether I'm doing this in Euler space or something, but I'm not actually sure. I've heard that the game uses axis rotation, which I know nothing about.
So I'm creating a mod for a game based on a somewhat dated version of Torque 3D (or at least I assume it's Torque 3D, the game is 3D).
One of the weapons in this mod is a "Wave Shot", which fires a single projectile where the crosshair is pointed (from the weapon's muzzle vector). In addition to that, it fires four more projectiles. Ideally, I want these five projectiles to form a + shape on the screen of the player who fired them; in other words, the vectors for the four additional projectiles should be rotated ten degrees from the muzzle vector in the directions right, left, up, and down, relative to the muzzle vector.
I have no bloody clue how to do this. I've gotten help from folks on the coding help forum of the game in question, but they haven't figured it out either.
How do I create a vector that is rotated relevant to the muzzle vector?
Here's the code so far. Sorry, I don't know how to mark anything up here.
I don't know how to calculate %vecrot1 through %vecrot4, hence this thread.
function vwaveImage::onFire(%this,%obj,%slot)
{
%projectile = vwaveProjectile;
%obj.playThread(2, shiftLeft);
//%obj.toolAmmo[%obj.currTool]--;
//%obj.AmmoSpent[%obj.currTool]++;
commandToClient(%obj.client,'bottomPrint',"<just:right><font:impact:24><color:fff000>Wave Shot<font:impact:34>c6" @ %obj.toolAmmo[%obj.currTool] @ " / " @ %obj.client.quantity["Vwaveshots"] @ "", 4, 2, 3, 4);
%vector = %obj.getMuzzleVector(%slot);
echo("vector is " @ %vector);
%vector1 = VectorScale(%vector, %projectile.muzzleVelocity);
echo("vector1 is " @ %vector1);
%objectVelocity = %obj.getVelocity();
%vector2 = VectorScale(%objectVelocity, %projectile.velInheritFactor);
echo("vector2 is " @ %vector2);
%vecrot0 = %vector1;
%vecrot1 =
%vecrot2 =
%vecrot3 =
%vecrot4 =
//NEED HELP HERE
echo("Vecrot0 is " @ %vecrot0);
echo("Vecrot1 is " @ %vecrot1);
echo("Vecrot2 is " @ %vecrot2);
echo("Vecrot3 is " @ %vecrot3);
echo("Vecrot4 is " @ %vecrot4);
for(%shell=0; %shell<5; %shell++)
{
%p = new (%this.projectileType)()
{
dataBlock = %projectile;
initialVelocity = %vecrot[%shell];
initialPosition = %obj.getMuzzlePoint(%slot);
sourceObject = %obj;
sourceSlot = %slot;
client = %obj.client;
};
MissionCleanup.add(%p);
}
return %p;
}
Please send help, I've been at this for a week with no progress.
EDIT: I'm not actually sure whether I'm doing this in Euler space or something, but I'm not actually sure. I've heard that the game uses axis rotation, which I know nothing about.
#2
That's why I made this thread. Please help.
04/26/2015 (12:13 pm)
Still not getting anything. It appears the problem is that I don't understand vector math at all.That's why I made this thread. Please help.
Torque Owner Robert Fritzen
Phantom Games Development
Draw a top down perspective and a side perspective, assume the muzzle point exists at <0, 0, 0> and the muzzle vector points in vhatever direction you want it to. From there you can draw it out and run the trig/vector math very easily to convert it into script form.