Author Topic: How to add length to a vector(NEW QUESTION ON PAGE 2)  (Read 1726 times)



I tried vectorAdd() but it doesn't seem to work
or is it just me that doesn't understand vectors
« Last Edit: October 25, 2013, 09:26:03 PM by Aide33 »

vectorScale( vector 3f, length ).

So, for example, vectorScale(%player.getMuzzleVector(),2); will get the position 2 torque units ahead of the player.

For vectors that aren't unit vectors (muzzlevectors and eyevectors are) use vectorNormalize() to get them in that form before scaling them.

Code: [Select]
function VectorExtend(%vec, %x)
{
    return VectorAdd(%vec, VectorScale(VectorNormalize(%vec), %x));
}

That will extend the vector by %x in the direction its pointing.
Explanation:
The vector is normalized, then scaled to the correct length. As we want to extend the vector, we simply add the original vector on to this.

[/spoonFeed]

The thing about that, boodals, is the muzzle vector is already normalized.

That is a general resource, not just for this one case. Anyone can use that anywhere and it should work.

Or, to get the same result, you could call vectorScale(vectorNormalize(%vec), %x+1);

Code: [Select]
                               serverPlay3D(SlapShot,%obj.getPosition());
%obj.unmountimage( 0 );
%obj.mountimage(HockeyStickImage, 0);
%objectVelocity = %obj.getVelocity();
%vector = %obj.getMuzzleVector(0);
%vector1 = VectorScale(%vector,40);
%vector2 = VectorScale(%objectVelocity,0.1);
%fvel =  VectorAdd(%vector1,%vector2);
%vel = VectorAdd(%fvel, "0 0 -10");
%p = new item()
{
dataBlock = PuckPickupItem;
           position = VectorExtend(%obj.getMuzzlePoint(0),3);
  sourceObject = %obj;
  sourceSlot = 0;
    client = %obj.client;
};
%p.setVelocity(%vel);
%p.schedulePop();
%obj.playThread(3, shiftRight);

I don't get why it doesn't work
I added the boodals code to the top of the file (not seen in the snip)
I don't get why it does this

I don't think vectorExtend is a default function

You want to use VectorScale(%vector, %length)

I'm pretty sure the length of the original %vector is ignored in vectorScale

I don't think vectorExtend is a default function

You want to use VectorScale(%vector, %length)

I'm pretty sure the length of the original %vector is ignored in vectorScale
I just said
I added the boodals code to the top of the file (not seen in the snip)
which is
Code: [Select]
function VectorExtend(%vec, %x)
{
    return VectorAdd(%vec, VectorScale(VectorNormalize(%vec), %x));
}

That will extend the vector by %x in the direction its pointing.
Explanation:
The vector is normalized, then scaled to the correct length. As we want to extend the vector, we simply add the original vector on to this.

[/spoonFeed]

getMuzzlePoint gets a muzzle point, not a muzzle vector.

What you want to do is add the muzzle point to the extended muzzle vector.

Lets say Muzzle Point is at (3, 5, 2), and Muzzle Vector is (1, 0, 0). Adding them together gives you (4, 5, 2), which is the correct location, however you are extending the point, which in effect moves it further from (0, 0, 0).

If you don't understand the difference and similarities between vectors and positions, I recommend reading this tutorial.

getMuzzlePoint gets a muzzle point, not a muzzle vector.

What you want to do is add the muzzle point to the extended muzzle vector.

Lets say Muzzle Point is at (3, 5, 2), and Muzzle Vector is (1, 0, 0). Adding them together gives you (4, 5, 2), which is the correct location, however you are extending the point, which in effect moves it further from (0, 0, 0).

If you don't understand the difference and similarities between vectors and positions, I recommend reading this tutorial.
OOOOOOOOOOOOOOOOOOOOOOOo
so VectorExtend(%obj.getMuzzleVector(0),3);??


It still does the same thing as before except the puck spawns farther away

It still does the same thing as before except the puck spawns farther away
Well you scaled the vector by 3, so of course it will spawn further away

Well you scaled the vector by 3, so of course it will spawn further away
no it spawns to the left or to the right of the player like in the image I posted
I don't get why