Author Topic: IF statement help  (Read 719 times)

Is there a way to make an IF statement that detects if the player/vehicle is moving forewords? Like the velocity from the eye node or something?


maybe if the player is pressing the key binded to go foreword?

You can detect a player's velocity or package the moveForward function, which looks like this:
function moveForward(%trueIfMovingForward)

You can detect a player's velocity or package the moveForward function, which looks like this:
function moveForward(%trueIfMovingForward)
That's client-side, I believe he wants server-side

Well here's a server-side ::isMovingForward
It works for vehicles, players, anything that moves I think

Code: [Select]
function ShapeBase::isMovingForward(%this)
{
%movingVector = %this.getVelocity(); //The direction we're moving
%movingX = getWord(%movingVector,0);
%movingY = getWord(%movingVector,1);

if(!%movingX && !%movingY) //We're not moving at all
return 0;

%forwardVector = %this.getForwardVector(); //The direction we're facing
%forwardX = getWord(%forwardVector,0);
%forwardY = getWord(%forwardVector,1);

%q1 = %movingX/%forwardX;
%q2 = %movingY/%forwardY;

if(mAbs(%q1-%q2) <= 0.01) //If %q1 and %q2 are within 0.01 of each other, to compensate for rounding
return 1;
else
return 0;

}

I was trying to make it so you could pass a perimeter, %angle, and you could move within that many degrees of where you're looking and it would still report true, but I couldn't figure that out.
This current function will report true only if you're moving in the same exact direction your facing


If you want this for that vehicle you made, just add '&& %obj.isMovingForward()' to the if that makes it fly if it passes, and if you want to to stop when you stop moving, I think add ' || !%obj.isMovingForward() ' to the other if
« Last Edit: August 18, 2011, 08:51:36 PM by Headcrab Zombie »

thank you once again :D

you sir, are incredible

edit: where do i put it in the script? lol
« Last Edit: August 21, 2011, 05:15:58 PM by Midway Sentinel »

Code: [Select]
if(ShapeBase::isMovingForward(YOURPLAYER)) {
   STUFFYOUWANTTODOIFPLAYERISMOVING
}
else
{
   STUFFYOUWANTTODOIFPLAYERISNOTMOVING
}

Correct?

If you want this for that vehicle you made, just add '&& %obj.isMovingForward()' to the if that makes it fly if it passes, and if you want to to stop when you stop moving, I think add ' || !%obj.isMovingForward() ' to the other if

So,

Code: [Select]
function DMTVCheckVelocity(%obj)
{
cancel(%obj.checkVelocitySchedule);
if(!isObject(%obj))
return;

if(vectorLen(%obj.getVelocity()) >= 1 && !%obj.isFly && %obj.isMovingForward())
{
%obj.mountImage(DMTVJetStreamImage1,0);
%obj.mountImage(DMTVJetStreamImage2,1);
%obj.playThread(0,"toFly");
%obj.isFly = 1;
}

if((vectorLen(%obj.getVelocity()) < 1 && %obj.isFly) || !%obj.isMovingForward())
{
%obj.unMountImage(DMTVJetStreamImage1,0);
%obj.unMountImage(DMTVJetStreamImage2,1);
%obj.playThread(0,"toIdle");
%obj.isFly = 0;
}

%obj.checkVelocitySchedule = schedule(100,0,DMTVcheckVelocity,%obj);
}

You might even want to take out the velocity checks
« Last Edit: August 21, 2011, 05:51:42 PM by Headcrab Zombie »