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

Does it have to be muzzle vector? There's always a player's forward vector for, well, the forward vector.
« Last Edit: October 24, 2013, 06:42:01 PM by Alphadin »

Post your related code.

Does it have to be muzzle vector? There's always a player's forward vector for, well, the forward vector.
He wants angle too. I'd use their eyevector.

No I need the muzzle vector

This is allll of the code
Code: [Select]
function VectorExtend(%vec, %x)
{
    return VectorAdd(%vec, VectorScale(VectorNormalize(%vec), %x));
}
                          
function Armor::onTrigger(%data,%obj,%slot,%val)
{
Parent::onTrigger(%data,%obj,%slot,%val);
//echo("onTrigger invoked");
if(%obj.getDatablock() == PlayerIceHockeyArmor.getID() || %obj.getDatablock() == PlayerGoalieArmor.getID())
{
//echo("yes he has a hockey player");
if(%slot == 2)
{
//echo("stopping him");
if(($Sim::Time - %obj.lastbrake) > 1)
{
serverPlay3D(Shave_Ice,%obj.gettransform());
%obj.setVelocity("0 0 0");
%obj.lastbrake = $Sim::Time;
}
}
}
%image = %obj.getMountedImage(0);
//Echo(%image);
if(%slot == 4)
{

//HOCKEY PASS
if(isObject(%image) && %image.HockeyStickWPuck)
{
%obj.hasPuck = false;
%obj.hasSportBall = false;
//echo("no puck :(");
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.getMuzzleVector(0),3);
  sourceObject = %obj;
  sourceSlot = 0;
    client = %obj.client;
};
%p.setVelocity(%vel);
%p.schedulePop();
%obj.playThread(3, shiftRight);
}
if(isObject(%image) && %image.HockeyStick)
{
if(%val)
%obj.playThread(3,shiftRight);
}
//GOALIE PASS
if(isObject(%image) && %image.GoalieStickWPuck)
{
%obj.hasPuck = false;
%obj.hasSportBall = false;
//echo("no puck :(");
serverPlay3D(SlapShot,%obj.getPosition());
%obj.unmountimage( 0 );
%obj.mountimage(GoalieStickImage, 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 Projectile()
{
dataBlock = PuckProjectile;
    initialVelocity = %vel;
    initialPosition = VectorExtend(%obj.getMuzzlePoint(0),3);
  sourceObject = %obj;
  sourceSlot = 0;
    client = %obj.client;
};
%obj.playThread(3, shiftRight);
}
if(isObject(%image) && %image.GoalieStick)
{
if(%val)
%obj.playThread(3,shiftRight);
}
}
}

and the ontrigger is in a package
« Last Edit: October 25, 2013, 04:07:01 PM by Aide33 »

Try this for your code:

Code: [Select]
%aim = %obj.getMuzzleVector(0);
%posScale = vectorAdd(vectorScale(%aim,0.1 * vectorLen(%obj.getVelocity())),vectorScale(%aim,10));
%position = vectorAdd(%posScale,%obj.getPosition());
%velScale = vectorScale(%aim,15);
%velocity = vectorAdd(%velScale,vectorLen(%obj.getVelocity()));
%p = new item()
{
dataBlock = PuckPickupItem;
position = %position;
sourceObject = %obj;
sourceSlot = 0;
client = %obj.client;
};
%p.setVelocity(%velocity);

The vector code you have there is highly irrelevant to what you're actually trying to accomplish, it's overcomplicated and wrong. Part of the problem is that you use ambiguous variable names, too.

Edit: Forgot that .getVelocity() method returns a vector, lol
« Last Edit: October 25, 2013, 04:38:48 PM by Treynolds416 »

thankyouthankyouthankyouthank you
I'll test it now

I have one more question now



(typo in the image 0 deg. not 90)
imagine the red guy is the player
how do I know if he is looking down below 0 degrees
« Last Edit: October 25, 2013, 09:23:26 PM by Aide33 »

thankyouthankyouthankyouthankyou
I'll test it now

I have one more question now



(typo in the image 0 deg. not 90)
imagine the red guy is the player
how do I know if he is looking down below 0 degrees


Just look at the last component of the muzzle vector.  That is the z component.  If it is less than zero, then it is down.

Just look at the last component of the muzzle vector.  That is the z component.  If it is less than zero, then it is down.
Thank you