Is it possible to set boolean state based on hit collision? (not overlap)

Hi,

I am having a hard time figuring out how to set boolean value based on collision hit. I am trying to prevent player from being able to move vehicle pawn when the pawn is not touching the ground. The contact with ground is done using physics rigid body simulation. I am initially able to flip the boolean value when the vehicle first touches the ground, as it lands on the ground, and then I can continually set that boolean value to True state as long as the event Hit keeps firing when the vehicle is constantly in contact with ground. But I have hard time figuring out how to detect when the collision stops.

I tried “IsValid” for the other Actor hit result, but that’s not evaluated if the Hit event doesn’t fire, and hit event doesn’t fire when it’s not in contact with anything else, so I can’t really use that either. I am currently using poor workaround with overlap, but it’s very sub-optimal.

Basically all I need is to continuously detect if my rigid body is colliding with anything else, and return boolean value based on that.

Thank you in advance.

I hope this helps some. It is basically timer created on event tick (i find this safer than timers from unreal). This code after some time sets “on the ground” vasriable to false. And sets it back to true when in certain distance to floor.

It is not tested, but should be something like this.
Also instead of UPVector for your actor you can use [0,0,1] to always pint down instead of local down for your vehicle actor.

Hehe, thank you very much. I am afraid it may be a little overkill though. Since it took a while to get the answer, I was able to figure a solution in the meanwhile :slight_smile:


While I am a blueprint beginner, and I am not well aware of performance implications yet, I feel like your solution is a lot of work to do every tick :expressionless: My question was specifically about if it’s possible to detect physics hit (not overlap) continuously.

That being said, I appreciate you taking the time to answer. That’s very rare on these forums.

Ahh performance for every tick. I handle it is about same fashion as that graph for ground contact.

I create my own slower on tick version. Connect it to dispatcher, and fire it with some integer (that just increments). And every actor (or script) that hooks to it ticks every nth dispatcher call.
So for eg i fire dispatcher every 0.25 sec. Thing like your in the air can be delayed up to 1 sec without real impact on game (it adds some randomness), so that code for “in the air” would check only every 4th dispatcher call. For that get integer (incrementing one) do modulo 4 on it and if its 0 fire “in the air”

It looks complicated but that with some other tricks let me increase number of asteroids from 30 to 400-500 in android game.
I tried same with unreal timers and they are not made for this, stuff gets messy and very easy to hang or crash. However unreal timers are perfect for fire and forget events.

I actually had issues if my detection was slower than 0.1 seconds. When my vehicle drives on the ground with physics, it has some friction. If I add force to it once it flies, even for a fraction of second, the friction is already gone, so it starts flying into the sky :slight_smile:

Ahh adding force with physics, it is very easy to make physics unstable. You have dedlta seconds for this reason, compensate your force added (multiply it by delta seconds) so you have constant force added over time.

For such thing you should fire line trace every tick, and decide if its on ground or not. Doing this for few vehicles will not have noticeable impact. IT usually starts slowing in around 70 up to 100 actors, but even then its like 1-2 fps.

My current workaround with do once node actually works. It happens on every tick. I had issues just when I tried overriding tick interval value :slight_smile: I don’t think delta seconds would really help here, as it’s not really side effects of the framerate dependency, but rather the fact that once collider stops colliding with ground, there is no other rigid body to have friction against, so in case you are still adding the force even though there is no collision anymore, the force has a larger impact since the friction is then gone.

But again, I have it already solved, and it works now. I guess two boolean value sets and one do once won’t bring my game to its knees even if it happens every frame :slight_smile: