Blockland Forums > Modification Help
Adding relative velocity (vectors)
(1/2) > >>
lordician:
I am quite stuck with some problem and i have searched everywhere but i am getting pretty confused on how to do this:
I have a vector but i want it to go the way of the other vector.
Even more specific: Vector for speed needs to be altered to go into direction of upVector.

I have tried to figure something out by looking at the code of Event_addRelativeVelocity but it didn't really help. :C
I also looked at the axisToEuler and EulerToAxis things but i can't really think of a way to do this.
It has been breaking my head a long time.

Can anyone please help me on my way?
Amade:
I'm not entirely sure what you're trying to do here, but if you're doing what I think you're trying to do...

--- Code: ---function Player::AddZVelocity(%obj, %amt)
{
%vel = setWord(%obj.getVelocity(), 2, getWord(%vel, 2) + %amt);
%obj.setVelocity(%vel);
}
--- End code ---
lordician:

--- Quote from: Amade on October 06, 2011, 04:28:00 PM ---I'm not entirely sure what you're trying to do here, but if you're doing what I think you're trying to do...

--- Code: ---function Player::AddZVelocity(%obj, %amt)
{
%vel = setWord(%obj.getVelocity(), 2, getWord(%vel, 2) + %amt);
%obj.setVelocity(%vel);
}
--- End code ---

--- End quote ---
Sorry, it must've been the time.

Thanks, but it is nothing what i need. :P

At the moment i have one vector being the static velocity upwards ("0 0 6" for example) but i want to have it applied 'dynamically'.
For example, a vehicle would instead of just go up no matter what go up in it's upvector.
So if it is angled, it will add velocity at that angle.
Amade:
Clockturn made a script that does this for me because I was doing something similar and completely baffled. Here you go:

--- Code: ---//by clockturn
function Player::getRelativePosition(%player,%vec,%slot)
{
if(getWordCount(%vec) != 3 || !isObject(%player))
{
return;
}
// X is left/right
// Y is forward/back
// Z is up/down
%x = getWord(%vec,0);
%y = getWord(%vec,1);
%z = getWord(%vec,2);

%scale = %player.getScale();
%sx = getWord(%scale,0);
%sy = getWord(%scale,1);
%sz = getWord(%scale,2);

%x *= %sx;
%y *= %sy;
%z *= %sz;

if(%slot $= "eye")
{
%yv = vectorNormalize(%player.getEyeVector());
} else {
%yv = vectorNormalize(%player.getForwardVector());
}
%zv = vectorNormalize(%player.getUpVector());
%xv = vectorNormalize(vectorCross(%yv,%zv));

if(%slot $= "eye")
{
%pos = %player.getEyePoint();
} else if(%slot !$= "") {
%pos = getWords(%player.getSlotTransform(%slot),0,2);
} else {
%pos = %player.getHackPosition();
}

%pos = vectorAdd(%pos,vectorScale(%xv,%x));
%pos = vectorAdd(%pos,vectorScale(%yv,%y));
%pos = vectorAdd(%pos,vectorScale(%zv,%z));

return %pos;
}
function Player::getRelativeVector(%player,%vec,%slot)
{
%pos2 = %player.getRelativePosition(%vec,%slot);
if(%slot $= "eye")
{
%pos = %player.getEyePoint();
} else if(%slot !$= "") {
%pos = getWords(%player.getSlotTransform(%slot),0,2);
} else {
%pos = %player.getHackPosition();
}
return vectorNormalize(vectorSub(%pos2,%pos));
}
--- End code ---
So for the example you just said, you would use %obj.addVelocity(%obj.getRelativeVector("0 0 6"));.
lordician:
Thanks for giving me this example.
Working it out without a good example is brain damaging. :P
Navigation
Message Index
Next page

Go to full version