Download

How to prevent double hit

I swing a stick at an incoming projectile, and a lot of the time there would be a double hit. I can tell because I play a sound on the collision. Also, when it happens I can see for a split second the projectile start to go one way, then on the 2nd hit it goes off in a weird direction. Like the stick moves ahead of the projectile after the first, then the back part of the stick 'hit’s the projectile again sending it backwards or sideways.

So my question is, how can I prevent this?

Sounds like this could be fixed with a ‘IsHit’ boolean at the beginning of your hit event. Just set the bool to true when theres a hit and dont play the sound if IsHit=True. Sounds like the double-hit could be occurring because the hit is being registered on more than one frame, so preventing more than one hit should clear it up. You could set the bool back to false after an arbitrary pause, just long enough to make sure only 1 hit is registered.

that’s what I am already doing. The sound isn’t the problem, it’s the double hit affecting the physics of the projectile

I recommend you use OnOverlap instead and write the logic that’s supposed to occur when the projectile overlaps with the stick

but if both the projectile and the stick both have collision, how will using onoverlap help with a double hit? The logic is just to prevent the sound from coming twice. There is no logic for the physics, the game just handles that. I need something like if the stick hits the projectile, don’t allow it to hit it again, but still allow the projectile to hit anything else it may run into

They won’t have blocking collision but should both overlap each other. That said, if everything works the way you expect and audio is the only issue, you can add a small delay before you allow your audio to execute again.

I think something is getting lost in translation. Audio is not the problem, I have a flag so it only gets played once.

The problem is, when I swing the stick at an incoming object (actor), and have physics and collision on both it and the stick, two hits happen a lot of the time very quickly in succession. I don’t have any logic to handle the physics of how the projectile reacts. The game engine just handles that.

Are you saying I should take collision off, then when they overlap, add it? I think there would still be double-hits. The stick needs to somehow register that it has hit the projectile, then not be allowed to hit it again. That would prevent a double hit.

I’ve built a racquetball game, and other various “hit ball with object” games using motion controllers, and the best way to handle that is by writing your own logic on how the ball should behave when it overlaps with the stick/racquet-object.

Ya that is what I figured how those games work, and was hoping to avoid.

thx for your help BTW. I was wondering if you could take a quick look at another problem:

nevermind, i found this:

For versions older than Oculus OVRPlugin v13: Navigate to Edit > Project Settings > Platforms > Android > Advanced APK Packaging, and add the following to the “Extra Settings for section” textbox: “”

1 Like