| Blockland Forums > Modification Help |
| IF statement help |
| (1/2) > >> |
| Midway Sentinel:
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? |
| Midway Sentinel:
bump |
| Midway Sentinel:
maybe if the player is pressing the key binded to go foreword? |
| dUMBELLS:
You can detect a player's velocity or package the moveForward function, which looks like this: function moveForward(%trueIfMovingForward) |
| Headcrab Zombie:
--- Quote from: dUMBELLS on August 18, 2011, 08:02:56 PM ---You can detect a player's velocity or package the moveForward function, which looks like this: function moveForward(%trueIfMovingForward) --- End quote --- 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: ---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; } --- End code --- 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 |
| Navigation |
| Message Index |
| Next page |