- Home /
What is the optimal way to get the hit point in a trigger collision?
Hello. I'm making a Hack & Slash game where I need to check every attack with triggers, because I control hit detection with animations and scripts. The thing is, that sometimes I want to check the hit position to create particles or for generating knockback direction. So I'm searching for the optimal solution without sacrificing performance to get that hit position.
What will be the most optimal?
When the trigger (hitbox) detects a collider (hurtbox), use Physics.Boxcast/ Physics.CapsuleCast/ Physics.SphereCast using the size of the trigger to get a RaycastHit. Then check if RaycastHit.collider is the same as the Collider detected inside the OnTriggerEnter function, and return RaycasyHit.point.
Use non kinematics rigidbody colliders with all constraints freezed. Then use OnCollisionEnter to get the contact points.
Thank you in advance!
Answer by Kishotta · Jun 27, 2017 at 02:23 AM
The easiest way would probably be to use Collision.contacts. I don't know if it's the most efficient, but the array has already been generated for you.
I tested the method with BoxCast I mentioned; but it doesn't work because BoxCast will not detect a collision with a collider if it is overlaped at the start of the sweep. So your solution is my only alternative :) But I'm still wondering if a rigidbody with all its constraints freezed its better in performance than a rigidbody whitout them freezed...