Author Topic: Get Relative Velocity  (Read 2173 times)

I want to get velocity relative to the forward vector.
Code: [Select]
%vel = %obj.getVelocity();
%fwdv = %obj.getForwardVector();
%dv = getWords(%vel,0,1);
%fv = vectorScale(%fwdv,%dv);
if(%fv > 0.15)
{
}
That doesn't seem to work.

The first thing I noticed is that you're using vectorScale wrong - the second argument should only be one number. You might want to read this tutorial.

Code: [Select]
%vel = %obj.getVelocity();
%fwdv = %obj.getForwardVector();
%fwdx = getWord(%fwdv,0);
%fwdy = getWord(%fwdv,1);
%x = vectorScale(%fwdx,%fwdy);
%y = vectorScale(%fwdv,0.25);
%fvel = vectorScale(fwdv,%x);
if(%fvel > %y)
{
New code; I still have no idea what I'm doing. I need to get the forward velocity and check if it is greater than 0.25.

i think someone once made a getRelativeVelocity(); function.


i think someone once made a getRelativeVelocity(); function.
OP did that :/
Code: [Select]
function player::getRelativeVelocity(%player,%xyz)
{
%x = getWord(%xyz,0);
%y = getWord(%xyz,1);
%z = getWord(%xyz,2);
%forwardVector = %player.getForwardVector();
%forwardX = getWord(%forwardVector,0);
%forwardY = getWord(%forwardVector,1);
}

function newcar::addRelativeVelocity(%newcar,%xyz)
{
%x = getWord(%xyz,0);
%y = getWord(%xyz,1);
%z = getWord(%xyz,2);
%forwardVector = %newcar.getForwardVector();
%forwardX = getWord(%forwardVector,0);
%forwardY = getWord(%forwardVector,1);
%newcar.addVelocity((%x * %forwardY + %y * %forwardX) SPC (%y * %forwardY + %x * -%forwardX) SPC %z);
}
Not sure if it works or not.



I think it was an event.
That would be setRelativeVelocity (by z0w0)
It's the opposite of what he needs

That would be setRelativeVelocity (by z0w0)
It's the opposite of what he needs
True. Any helpful comments?

I can't think of an easier way other than using lots of trig in a complicated function

Can't I just do something with the forwardVector? Like condense the directional velocity
Code: [Select]
%vel = %obj.getVelocity();
%dv = getWords(%vel,0,1);
and then somehow fit it into this current velocity code
Code: [Select]
%cv = vectorScale(%obj.getForwardVector(),%dv);?

So you want the velocity but only the part matching the forward vector or something? I'm utterly confused by the terms here but I think this is what you want?
Code: [Select]
%velocity = %obj.getVelocity();
%forwardvector = %obj.getForwardVector(); //Returns normalized x and y of player's orientation as regards to forward. Z is always 0
%forwardx = getWord(%forwardvector,0);
%forwardy = getWord(%forwardvector,1);
%relvelocityx = vectorScale(%velocity,%forwardx);
%relvelocityy = vectorScale(%velocity,%forwardy);
%relvel = %relvelocityx SPC %relvelocityy SPC "0";
if(VectorLen(%relvel) > 0.25))
{}
« Last Edit: February 16, 2013, 12:43:01 PM by DYLANzzz »

he probably wants a velocity check relative to the object's forward velocity. as in, to check how fast its moving forward.

he probably wants a velocity check relative to the object's forward velocity. as in, to check how fast its moving forward.
This. At some point I'll want to know left and right as well, but for now just forward or backward velocity.