I have two sword-like colliders in a game and want to render an effect when a user crossing them in the touch zone. My swords has trigger colliders (trigger = true) and are interacting with other world objects which has trigger colliders (trigger = true), in collision with other objects they are destroyed, or effects are rendered. The issue is when I try to render an effect of swords crossing when you touch each blades together. I’m getting the OnTriggerEnter/Stay/Exit events but unable to get touch points, these are for some reason available only in the OnCollisionEnter/Stay/Exit events which are not applicable for me as long as I’m using trigger colliders (this swords has lots of interactions with the world and I’m unable to make them trigger = false).
The question is: having two given colliders (and associated game objects, meshes and rigid bodies), and knowing that the colliders has touched each other (OnTriggerEvent is called) how can I get the intersection of these two colliders. I want to render an effect at that point, or rather center point of the intersection (like sparks) but let them go through each other.
I’ve found lots of suggested solutions but none worked for me so far:
- Make them trigger = false, add non-kinematic rigit body and handle OnCollisionEnter - didn’t work because it breaks the game mechanics with the rest of the world, swords now can be pushed by other objects and can push them instead of interacting by rules defined in the trigger event.
- Raycast - doesn’t work, swords are not points, they are planes, so I need to get the whole collider intersection with the other
- BoxCast - the closest I was able to get, I’m sending BoxCasts to 4 sides of the sword (up, -up, right, -right) and it gives me approximate points but they are no precise and it doesn’t work when swords are actually inside each other (you can swing a swords and pass through another blade)
- ClosestPoint from first collider to every point of the mesh vertices, and then get another collider and do the same and then find mid between two points. Didn’t work either - the mesh is a cylinder and it doesn’t have a lot of vertices in the middle of the sword mesh, the result is unaccepted.
- Vector3.Cross for both vectors of the swords - theoretically I can draw an vector from handle to the tip and cross it with another sword, but it gives me really weird result vector and I’m not sure how to turn it into the cross point between two colliders (or at least two vectors).
It sounds like an standard 3d math problem but I’m having really hard time solving it
Please advise.