Download

Check if actor in air

I was thinking of checking if the actor (none character) is currently NOT colliding with anything to find out if it’s in the air, but I’m having some trouble with that. There’s the Event Hit node which fires when something is colliding, but it’s naturally not executing if nothing is colliding. I don’t know how to reverse that logic in blueprints.

What’s the best solution here?

There is an “isFalling” node if I remember correctly.

Found that as part of Character Movement, but I need it in a standard actor.

You could try tracing from the lowest point of collision shape/mesh to the ground and if the distance ray traveled before hitting something is greater than 0(might be better to use 1, depends on how accurate is the actor aligned to the ground) - it means he’s in air.

Though it would probably be performance hungry if you’re going to use a lot of active actors of this kind.

You don’t need to do any of this, it’s a simple Logic problem. All you need is effectively, a NOR gate.

Use a hit event to detect when the actor DOES collide with something. Allow that to switch the state of a bool, which changes the output of a Branch. The output of the Branch is true or false, and if you want it to be constant, you can fire event Tick through it.

What you’ll need to remember of course is that Overlap/Hit events generate once, when the event happens. You’ll need to use a delay to reset the branch and rely on the hit event to set it back again if you’re still colliding with something.

For a simple object, you can use a sphere trace of some kind and detect when that trace is touching anything, by comparing it’s radius to the radius you specify. Either way, these are things you’ll have to do every frame, and as such will impact performance relative to how many of these actors you have. It might be worth looking at how the C++ code checks to see if the character is flying, but it’s probably just a capsule trace that works in the same way.

Surely I’m missing something really easy. Actor is colliding already, it’s just a matter of finding out when it’s not. I could do it with a variable that is false by default, then set it to true when Event Hit event fires. Problem is, how do I set the variable to false again when the event is not firing anymore? Seem to have a bit of knot in my brain on how to do that.

Exactly that, you can use a Delay to reset it after a short period of time.

Thanks, the tick event might be what was missing from my thinking. I’ll try again.

Or that, thanks :slight_smile:

Character movement component checks for floor every tick, and what it does is downward line trace. That is little bit more complicated than that. Check UCharacterMovementComponent::FindFloor
Regarding checking collisions to see if actor is in the air… that’s little bit weird. Actors are always able to collide with other actors, using collisions to check if actor is in the air in this case would involve a lot of various checks, and it looks much more like a hack than a proper solution for this. But anyway, everything depends on your goals.

Good point there about colliding with other things… a Find Floor style approach may be a better alternative.