Heres a little function I whipped up
you must provide the forwards vector, then the players upwards vector and then the dimensional shift
(shift [x,y,z] [away from and towards the origin,left and right along the origin,up and down along the origin])
function vectorRelativeShift(%forwards,%up,%shift)
{
return vectorAdd(vectorAdd(vectorScale(%forwards,getWord(%shift,0)),vectorScale(vectorCross(%forwards,%up),getWord(%shift,1))),vectorScale(%up,getWord(%shift,2)));
}
the above function should be used but here is a readable format of the function so that you can understand what is going on
function vectorRelativeShift_readable(%forwards,%up,%shift)
{
%xShift = getWord(%shift,0);
%yShift = getWord(%shift,1);
%zShift = getWord(%shift,2);
%xMod = vectorScale(%forwards,%xShift);
%yMod = vectorScale(vectorCross(%forwards,%up),%yShift);
%zMod = vectorScale(%up,%zShift);
return vectorAdd(%xMod,vectorAdd(%yMod,%zMod));
}
Here is a code example of how to use it, this makes the gun fire 2 projectiles one slightly to the left and the other to right
function gunImage::onFire(%db,%pl,%slot)
{
%muzVec = %pl.getMuzzleVector(%slot);
%muzPos = %pl.getMuzzlePoint(%slot);
%muzUp = %pl.getUpVector();
%pvel = %pl.getVelocity();
%proj = %db.projectile;
%vel = vectorAdd(vectorScale(%pvel,%proj.velInheritFactor),vectorScale(%muzVec,%proj.muzzleVelocity));
%left = vectorRelativeShift(%muzVec,%muzUp,"0 -0.2 0");
%right = vectorRelativeShift(%muzVec,%muzUp,"0 0.2 0");
%p = new Projectile()
{
datablock = %proj;
initialPosition = vectorAdd(%muzPos,%left);
initialVelocity = %vel;
sourceObject = %pl;
sourceSlot = %slot;
client = %pl.client;
};
missionCleanup.add(%p);
%p = new Projectile()
{
datablock = %proj;
initialPosition = vectorAdd(%muzPos,%right);
initialVelocity = %vel;
sourceObject = %pl;
sourceSlot = %slot;
client = %pl.client;
};
missionCleanup.add(%p);
}