Author Topic: Offsetting a vector  (Read 960 times)

Alright, I'm absolutely stuff with vectors.
I'm trying to get a position, and then offset it by "X Y Z" coordinates, but to keep said offset for every rotation it could possibly be in.

The offset coordinates I'm looking for in this case is (-1,1) and (1,1), a whole 1 X unit offset from the 1 Y unit, as it's to the "left" here, and a whole -1 X unit offset from the 1 Y unit, as it's to the "right" here.

Since the line here is rotated by 45 degrees, the new coordinate set is offset too.
The offset coordinate here would be (0,~1.4) for the offset line going "left" from the solid line. The other offset coordinate would be (~1.4,0) for the offset line going "right" from the solid line.

This makes good sense in a 2d space, but I have no idea how to implement it into a 3d environment.

What I'm ultimately trying to accomplish here is to take a muzzlePoint, and then fire a bullet from the left, and from the right, as I haven't been able to find anything to refer to several different muzzlePoints in one image.

Look at the infectonator I made a while back: http://forum.blockland.us/index.php?topic=291855.0

The needle projectile has spread to it. You could justify this spread-fire to fire offset left, then middle, then right, etc

Look at the infectonator I made a while back: http://forum.blockland.us/index.php?topic=291855.0

The needle projectile has spread to it. You could justify this spread-fire to fire offset left, then middle, then right, etc
this is spread, not offset, when i get home i will post some code here that i wrote for offsetting muzzle points

Look at the infectonator I made a while back: http://forum.blockland.us/index.php?topic=291855.0

The needle projectile has spread to it. You could justify this spread-fire to fire offset left, then middle, then right, etc
This isn't what I'm going for. Spread is easily the simplest thing to do, there's too many addons to count that actually have spread. I'm not looking to fire left and right, I'm looking to fire from left and right in order to simulate two different muzzle points.

this is spread, not offset, when i get home i will post some code here that i wrote for offsetting muzzle points
Thank you.
« Last Edit: January 31, 2016, 10:26:05 PM by Alphadin »

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])
Code: [Select]
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
Code: [Select]
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
Code: [Select]
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);
}

Heres a little function I whipped up
you must provide the forwards vector, then the players upwards vector and then the dimensional shift
-snippy-
It started working beautifully when I changed
%muzVec = %pl.getMuzzleVector(%slot);
to
%forVec = %pl.getForwardVector();

Thank you.
...
ORAORAORAORAORAORAORAORAORAORA
« Last Edit: February 01, 2016, 12:30:38 AM by Alphadin »

It started working beautifully when I changed
%muzVec = %pl.getMuzzleVector(%slot);
to
%forVec = %pl.getForwardVector();
I am going to guess the reason for this is you didn't properly specify your muzzlePoint on that model

I am going to guess the reason for this is you didn't properly specify your muzzlePoint on that model
Didn't want to. I was going to have it fire from eye point



actually I just forgeted up the model in blender yeah
but it just so happened that id be better off using eye point anyways
EDIT: thinking back on it, I'm pretty sure I was using getMuzzlePoint instead of muzzle Vector....
« Last Edit: February 01, 2016, 01:07:23 AM by Alphadin »