Author Topic: [Not Solved] Detecting if you're in midair  (Read 1750 times)

Hi BLF, I've been trying to solve this issue and Search didn't help at all. I want to find out if the player is off the ground in their vehicle. The two ways that came to mind were to detect changes in the z axis position/velocity or to get the distance from the ground. I tried the z-axis method, but it gives false-positives if you're scaling a hill (i'm dumb).

function Player::StuntLoop(%player, %lastpos)
{
   %car = %player.client.car; //%car is defined, don't worry

   %pz = mFloor(getWord(%car.getPosition(), 2));
   %z = mFloor(getWord(%lastPos, 2));

   if(%pz != %z)
      talk("Airborne!" SPC %pz SPC "!=" SPC %z);
//   else
//      talk("Not Airborne!" SPC %z SPC "==" SPC %pz);

   %lastPos = %car.getPosition();
   if(isObject(%player))
      %player.schedule(500, stuntLoop, %lastpos);
}


I couldn't figure out how to go about the other method. Anyone care to help?
I feel like there is an extremely easy way to do this like it's a default function or something. Badspot did it somehow with the mid-air kill notification. I need to find an efficient way to do it because I'm tracking air-time on vehicles, and to do that I'd need to make it a loop.
« Last Edit: June 11, 2016, 02:18:43 PM by Johnny Blockhead »

i (might) be wrong but i think there's a way to check if the player is grounded
that might not help in a vehicle though

you have to do a raycast check. i would hammer out an example but i can't right now

you have to do a raycast check. i would hammer out an example but i can't right now
Thanks for responding. I tried to do this but I can't get it to work. I'm a bit tired.
function Player::StuntLoop(%player)
{
   %car = %player.client.car;

   %pos = %car.getTransform();
   %mid = vectorScale("0 0 -1", 1000);
   %raycast = containerRaycast(%pos, vectorAdd(%pos, %mid), $Typemasks::ALL, %car);
   %ground = getWords(%raycast, 1, 3);

   //talk(%pos SPC %mid SPC %raycast SPC %ground);
   %dist = mFloor(vectorDist(%pos, %ground));
   talk(%dist);

   if(%dist > 1)
      talk("You're in midair!");
   if(isObject(%player))
      %player.schedule(500, stuntLoop);
}

It just spits out a random ass number that fluctuates between 1-3 and the early 100s

instead of $TypeMasks::All, try doing ($TypeMasks::FxBrickObjectType | $TypeMasks::TerrainObjectType $TypeMasks::VehicleObjectType).
it'll only hit bricks, fxplanes (the ground), and vehicles

instead of $TypeMasks::All, try doing ($TypeMasks::FxBrickObjectType | $TypeMasks::TerrainObjectType $TypeMasks::VehicleObjectType).
it'll only hit bricks, fxplanes (the ground), and vehicles
Thanks, I tried doing what you suggested and then getting rid of the vectorDist crap and just subtracting Z values. It works!
function Player::StuntLoop(%player)
{
   %car = %player.client.car;
   %pos = %car.getTransform();
   %mid = vectorScale("0 0 -1", 1000);
   %raycast = containerRaycast(%pos, vectorAdd(%pos, %mid), $TypeMasks::FxBrickObjectType | $TypeMasks::TerrainObjectType, %car);
   %ground = getWords(%raycast, 1, 3);
   %dis = mFloor(getWord(%pos, 2) - getWord(%ground, 2));

   if(%dis > 0)
   {
      %player.client.bottomPrint("\c2You're in midair!");
   }
   else
      %player.client.bottomPrint("\c0You aren't in midair!");

   if(isObject(%player))
      %player.schedule(500, stuntLoop);
}


Edit: It doesn't seem to work as well as I thought. If it's anything but modter/environment ground under the car, it detects that you are midair. It just goes through the brick. This happens even on $Typemasks::ALL. Any ideas? It works if the vehicle is slanted.

https://gfycat.com/ImperturbableFixedAmericangoldfinch
« Last Edit: June 11, 2016, 02:11:14 PM by Johnny Blockhead »

Put an echo on the distance var, what does it say when you are on the ground?

Put an echo on the distance var, what does it say when you are on the ground?
When I'm on the ground it's zero, when I'm on modter it's zero, when I'm on any other brick it's greater than that. It's acting as if that regular brick doesn't even exist, and is just getting the distance from the ground.

Relevant code:
   %pos = %car.getTransform();
   %mid = vectorScale("0 0 -1", 1000);
   %raycast = containerRaycast(%pos, vectorAdd(%pos, %mid), $TypeMasks::ALL, %car);//$TypeMasks::FxBrickObjectType | $TypeMasks::TerrainObjectType
   %ground = getWords(%raycast, 1, 3);
   %dis = mFloor(getWord(%pos, 2) - getWord(%ground, 2));

Edit: Nevermind.

Basically, you're going to have to get the position of the brick and do some math with the brick's height to get the correct distance (%dis) from your player to the brick.
« Last Edit: June 12, 2016, 01:54:58 AM by elm »

Sometimes raycasts won't pick up an object if the raycast starts on the surface of that object (or inside of it). Try doing %pos = vectorAdd("0 0 0.1", %car.getPosition());

Also you can get the ground distance without needing getword. Just do %dis = mFloor(vectorDist(%pos, %ground)); you can also vectorAdd -0.1 to %pos in that if you want it to be perfectly accurate.

Also I suggest against using TypeMasks::All since that will hit invisible objects like triggers, physical zones, spawn spheres, etc.
« Last Edit: June 12, 2016, 03:39:17 AM by Pecon »

Easiest way is to just check the vertical speed.
But it also triggers when you are walking down or up a ramp.

So depending on what you need it for, it could work.