detecting a players position
#1

Ok, basically i want to know how i would go about detecting if a player is standing on the ground. (rather than mid air jumping or falling from a building)
Reply
#2

or at least an idea of how i could do this. Anyone? I thought anims.. but there are a lot of anims for standing
Reply
#3

I guess use onplayerupdate, save their last position with SetPVarFloat


Код:
stock Float:Distance3D(Float:x1, Float:y1, Float:z1, Float:x2, Float:y2, Float:z2, bool:sqrt = false) {
	x1 -= x2;
	x1 *= x1;
	y1 -= y2;
	y1 *= y1;
	z1 -= z2;
	z1 *= z1;
	x1 += y1;
	x1 += z1;
	return sqrt ? floatsqroot(x1) : x1;
}

public OnPlayerUpdate(playerid)
{
    new Float:Cx,Float:Cy,Float:Cz;
    GetPlayerPos(playerid,Cx,Cy,Cz);

    if (Distance3D(GetPVarFloat(playerid,"xpos"),GetPVarFloat(playerid,"ypos"),GetPVarFloat(playerid,"zpos"),Cx,Cy,Cz)>0.01) {
         SetPVarInt(playerid, "moving", 1);
    }
    else {
         SetPVarInt(playerid, "moving", 0);
    }
    SetPVarFloat(playerid,"xpos",Cx); 
    SetPVarFloat(playerid,"ypos",Cy);
    SetPVarFloat(playerid,"zpos",Cz);
return 1;
}
Then to use it:

Код:
if (GetPVarInt(playerid, "moving")==1) {
 //... Do somthing
}
That >0.01 may need tweeking
Reply


Forum Jump:


Users browsing this thread: 1 Guest(s)