Quantcast
Channel: Questions in topic: "contact"
Viewing all articles
Browse latest Browse all 75

Getting surface normal from collision

$
0
0
When a collision event is triggered, you are returned a list of contact points, from which you can get normals. Unity's manual describes this as the "Normal of the contact point." Not very descriptive. I have always assumed this was the surface normal of the opposite collider at the point of collision, however this does not seem to be the case. ContactPoint.normal doesn't seem to give the actual surface normal, but rather some kind of impact normal. In other words, depending on the angles of impact, the normal returned can change. I did a test with a sphere collider and a ramp (rotated flattened box collider). The ramp was rotated to have a slope of 45 degrees. I made the sphere collider "walk up" the ramp and output the slope of the surface derrived from the contact normal as it pushed its way up the ramp. At first the results were as expected -- returned angle was 45 degrees. Then I disabled and re-enabled the sphere collider game object and the results changed. The impact returned different values now. The angle compared to Vector3.up would jitter +- 10 degrees as the sphere pushed up against the ramp. Visualizing this with a short ray at the point of contact showed a line that danced slighly on the vertical axis. The only reason I noticed this was because I tried my collision with another test sphere I was using for doing some character movement tests. This sphere was never able to get the stable, smooth 45 degree result returned like my simpler sphere above. When pushing against the ramp, I'd get about a 50+ degree angle returned, but when I stopped pushing against the ramp, it would drop back to the correct 45 degrees. Every time I pushed up against the ramp, I'd see the incorrect slope angle returned. The only way I've found to reliably get the surface normal is with a raycast. Am I missing something here? It sure would be a lot simpler if ContactPoint.normal just returned the surface normal of the polygon it collided with. I guess you could also get the surface normal from a mesh collider by getting the triangle list and normal list, but this seems overly complicated.

Viewing all articles
Browse latest Browse all 75

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>