I’ve read a few posts on a similar question but most seem to talk about box colliders and sides. in my case the collider would be a sphere.
Would using raycast tell me what direction the hit occurred on the sphere collider. is this even possible?
I’ve read a few posts on a similar question but most seem to talk about box colliders and sides. in my case the collider would be a sphere.
Would using raycast tell me what direction the hit occurred on the sphere collider. is this even possible?
The collision object you are passed in OnCollisionEnter contains a field called Contacts. A ContactPoint class has a Point field (of type Vector3). To find the incoming direction of the hit, subtract the contact point’s position from the that of the colliding object.
You can find the direction the sphere was hit from, by finding out the direction of the velocity of the projectile that hit it. Simply implement OnCollisionEnter
method in the collider that is going to get hit, and find the velocity of the colliding object using it’s rigid body. Remember you’ll have to inverse that vector to get the absolute direction, but that depends on what you plan on doing with it.