Author Topic: Check if player is moving  (Read 1411 times)

as the title says, is there a way to check if a player is moving or not? If so, can you post how?

Well, it simply needs two position checks. Then do whatever you want to do if the coordinates are different.

if(vectorLen(%player.getVelocity()) > 0)
{
     //player is moving
}

Keep in mind that there's no way to check(without a client sided mod) if they're moving using their move keys. Just if they're moving in general.

Keep in mind that there's no way to check(without a client sided mod) if they're moving using their move keys. Just if they're moving in general.
I've almost got server sided move key detection working (for default player speed anyway). I'll post it on this board when it's finished.

I've almost got server sided move key detection working (for default player speed anyway). I'll post it on this board when it's finished.
What.
I would like to see this.
I mean you can kind of calculate it when the player is on the ground i guess using the direction of the velocity and the player's forward vector, which is kind of what i did for some dodge move code, but it is not quite perfect.

What.
I would like to see this.
I mean you can kind of calculate it when the player is on the ground i guess using the direction of the velocity and the player's forward vector, which is kind of what i did for some dodge move code, but it is not quite perfect.
It's not in any state to post right now unfortunately but I can tell you what I'm trying because it's simple in theory. I'm getting the angle between a vector created by the players velocity and their forward vector, then checking that against the players rotation. The size of the angle is what I'm hoping makes it accurate and the velocity vector is enough to determine the movement keys they are holding (after some fine tuning on what the angle limits are for each direction).

I had a different method fully working with a massive switch statement for every direction but it was inaccurate at certain player rotations and inefficient so this new one will be better.
« Last Edit: June 22, 2016, 11:08:16 PM by Jervan »

Sounds very similar to what i did:
Code: [Select]
%pi = 4 * mAtan(1, 1);
%rotN = vectorNormalize(%rot);
%velN = vectorNormalize(%vel);
%rotX = getWord(%rotN, 0);
%rotY = getWord(%rotN, 1);
%velX = getWord(%velN, 0);
%velY = getWord(%velN, 1);
%atan1 = mAtan(%velY, %velX);
%atan2 = mAtan(%rotY, %rotX);
%angle = %atan2 - %atan1;
if (%angle > %pi)
%angle -= 2 * %pi;
else if (%angle < -%pi)
%angle += 2 * %pi;
%angle = mRadToDeg(%angle);
//echo("Velocity:" SPC %vel SPC "| Rotation:" SPC %rot SPC "| angle:" SPC %angle);
if (%angle < -5 && %angle > -100)
{
echo("Step Left");
%velocity = %player.getMaxSideSpeed() * 2;
%player.doDodge(vectorNormalize(%player.getLeftVector()), %velocity, %isOnGround, %data.canTeleDodge);
}
else if (%angle > 5 && %angle < 100)
{
echo("Step Right");
%velocity = %player.getMaxSideSpeed() * 2;
%player.doDodge(vectorNormalize(%player.getRightVector()), %velocity, %isOnGround, %data.canTeleDodge);
}
else if (%angle >= 100 || %angle <= -100)
{
echo("Step Back");
%velocity = %player.getMaxBackwardSpeed() * 2;
%player.doDodge(vectorNormalize(vectorScale(%player.getForwardVector(), -1)), %velocity, %isOnGround, %data.canTeleDodge);
}
Though i am pretty sure the calculations can be done more efficiently.
It just took a whole while for me to understand it and get it right.

What about stepping forward?

What about stepping forward?
The angle would be very small or non-existant, same for going backwards. Both need another type of check once the angle isn't available.

For my purpose i did not need forward, sorry.

You could also find the movement direction like this (not tested)

Code (30 lines)
%velocity = setWord(%player.getVelocity(), 2, 0);

if(vectorLen(%velocity) < 0.1)
{
    //no movement
}

%rotation = %player.getTransform();
%rotation = setWord(%rotation, 6, -getWord(%rotation, 6));
%localVelocity = matrixMulVector(%rotation, vectorNormalize(%velocity));

%x = getWord(%localVelocity, 0);
%y = getWord(%localVelocity, 1);

if(%x > 0.707)
{
    //going towards relative +x
}
else if(%x <= -0.707)
{
    //going towards relative -x
}
else if(%y > 0.707)
{
    //going towards relative +y
}
else
{
    //going towards relative -y
}


Though that's probably not what OP is asking for, he just wants to know whether the player is moving at all
« Last Edit: June 23, 2016, 11:51:10 AM by Zeblote »