Hello, I’ve been having an issue where trigger colliders have been passing through objects at low framerates and I don’t know how to fix this. I’ve tried switch it to a non-trigger collider which is almost working but then the problem is I don’t want collision physics with them, just to be able to apply force and trigger when hitting something else, but it’s pushing stuff it hits. How can I fix this? Any help is much appreciated.
Are you using discrete collision checking?
If so, that is performant but not fully accurate. Use continues for important or small collisions
I’m using continuous collision detection.
Continuous Collision Detection cannot work with triggers. Continuous requires the body be stopped/impacted at the contact point but there’s no collision response with triggers.
The frame-rate won’t affect physics if you’ve got it set to simulate during the fixed-update (default). Only setting large velocities could affect it as it’ll potentially step over (tunnel) the target.
You should use queries for this if you’re performing large steps with low frame-rates.
Yeah I think I’ll try using queries. I also noticed that in my trigger system the trigger would sometimes go over the collider and trigger the hit effects inside the object rather than on the outside of out. How would you recommend using queries for fast moving projectiles hitting obstacles and other projectiles?
Impossible to answer that beyond saying use queries. You can cast all the colliders on a specific Rigidbody2D, a specific collider, specific shapes or line/ray.
Ok, thanks for the help!
If you have a specific set-up, I’d be happy to advise though if you provide details.
I didn’t want my previous answer to sound evasive.
Hello again, I’ve set up a new system where I check on the projectiles in Fixed Update with an overlap box on them and I’m still having issues with the projectiles going through colliders even at decent frame rates if the colliders are relatively small. How can I use a query like overlap box and have it not go through small colliders? Thanks again for the help.
An overlap query won’t help you if you’ve already stepped over a collider (tunnelled). This is why I mentioned you should use casts i.e. bodycast, collider-cast, box-cast, raycast (etc) and filter by whatever you need.
The only issue I have with that though is that some projectiles home onto enemies so they turn, so a raycast wouldn’t always be able to work there.
You only cast for a single physics step before the simulation, this is no different than what physics is doing.
“projectile velocity * time-step”. It won’t turn and move during a simulation step. Physics doesn’t turn/move at all. It moves using linear velocity and rotates using the angular velocity which isn’t a curve.
Note you dou don’t have to use raycast as that’s just a line. If it’s approximate to what collider you’re using then fine but if you’re using something else then use the collider-cast.
I’m a bit confused here because I’m trying to detect when my projectile hits something and it doesn’t go infinitely fast, so how should I implement a cast system that only triggers when it’s over something? I’m currently using a collider2d cast and just setting the distance to 0 so it triggers only when it’s over something because when I use casts it’ll trigger before it reaches the object the cast hit. Sorry for the questions and thanks for helping again.
Oh, are saying I should use the collider cast to cast between the two points the projectiles were every frame to check if it hit anything?
You want to know if you’ll hit a trigger in the next simulation step (future), not if you jumped over it previously by checking for overlap (past). To do this you’ll cast from the current position to a position in the future!
Assuming physics is running during the FixedUpdate (default) then you need to simply cast in the direction of the projectile velocity with a distance of “velocity * Time.fixedDeltaTime”.
direction = body.linearVelocity
distance =body.linearVelocity * Time.fixedDeltaTime
Yay it works! Thanks for sticking with me there lol. I just put this in Fixed Update and it works great!
projCol.Cast(projRb.linearVelocity, filter, results, projRb.linearVelocity.magnitude * Time.fixedDeltaTime);