How to detect when an actor is NOT hit?

I’m trying to implement a “near miss” mechanic where the player gets points for driving very close to other vehicles but NOT collide with them. The problem is the score is given even when the player hits the other vehicle, so how do i check if the actor is NOT hit so i can use it as a condition?

You could have a collision hull that’s slightly larger than the car. If they overlap that, but no hit, that’s it?

1 Like

I tried doing that but then you could easily get points by crashing into the other cars. I don’t know how other racing games implement it where if you scratch the other car you don’t get points, you have to narrowly miss it.

How could that be? If you overlap the collision, but don’t hit, surely that’s what you need.

Yes, if you start overlapping the larger collision hull (OnBeginOverlap), then you can set some bool along the lines of “IsNear” to true. Then while this IsNear bool is true, you keep checking for hit with the actual solid, smaller collision hull.

If you hit the smaller hull, you set some another bool, for example “HasBeenHit” to true.

Then once you end overlap (OnEndOverlap) with the larger, overlap collider, you check if there was a hit to the care while you were near by checking if the IsNear was set to true, and if there was a hit, you do nothing, and if there wasn’t a hit, you give player score.

In other words, while you are near the other car, which you can detect by overlap of the larger hull, you keep testing if there was a hit to the smaller hull, and only when you stop being near, when the overlap with the larger hull ends, you decide whether to give player score or not.

2 Likes

How do I check if there was a hit? The only node I can find is Event Hit which doesn’t return a bool like “Is Hit”.

You just use event hit to set the whatever bool you create to true.

1 Like

I did as you suggested, but I found that my “is hit” bool would not set to true no matter what, whether I used On Hit or On Component Hit, so it would always return false and give points every time I hit a car.

I even tested it with a print function but it didn’t print the string at all. What is going on?

Collision settings is not right? Check both interacting elements and see what blocks what.

Both are set to block everything including each other’s object type, and generate hit events is on.

Update: I managed to make it work by calling the On Hit event in my player BP instead and modifying the bool value from there. Not sure why but it works.

You have just few cars, so do not spamm collision overlaping checks.
Report all car locations to some actor, keep those in array. Or do get all actors of class (AI car) and calculate distance to player car.
When some AI car is close to player car do either collision check for box around player or line traces around.
One (larger) distance from player to check for nearmiss and just barely bigger than model for colision with player.

Count near miss only when bigger is overlaping and smaller not. Also wait for enemy car to be further than some distance to score nearmiss.

ps.
And do not code hacks that work but you do not know why, this will bite you in da butt later when you have lots of code that depends on some weird conditions which worked for small code size but suddenly stops.

2 Likes