Facepunch / sbox-issues

178 stars 12 forks source link

Contact Point in TraceResult #2574

Open sndrec opened 2 years ago

sndrec commented 2 years ago

For?

S&Box

What can't you do?

Currently, the TraceResult structure contains a lot of useful information! But there's one thing that would be really useful to have for dealing with certain situations that come up often with objects that move into the player, especially triangle meshes.

How would you like it to work?

Contact Point should return the closest point on the surface of the thing that you collided with, even if you started solid. Here's a diagram I drew, assuming a sphere trace.

featurerequest1

featurerequest2

What have you tried?

In my marble roller gamemode, Rolled Out: Source 2, I use a trick involving a line trace from the center of the ball, in the direction of the hit normal, with a length equal to the ball radius. If that line trace hits anything, it can be assumed the ball started solid, and our line trace will find an assumed contact point. I can move the ball along the hit normal of the original sphere trace, from the hit position of the line trace, by the radius of the ball, which (usually) fully depenetrates it. When interacting with concave geometry, you might have to iterate this a few extra times to fully depenetrate the ball.

In practice this works very well, but breaks down for any other trace shape. Contact Point would be very useful for a capsule trace, a common player collision body shape (and what I intend to use in projects moving forward)

Additional context

No response

yuberee commented 2 years ago

To me it looks like this is what PhysicsBody.ClosestPoint( Vector3 ) would do, have you tried it?

sndrec commented 2 years ago

To me it looks like this is what PhysicsBody.ClosestPoint( Vector3 ) would do, have you tried it?

From what the documentation says, this function only works on convex bodies, not triangle meshes. Additionally, there's still the problem of finding the correct point to check the closest point from - you wouldn't want to check from the center of a capsule, for example, if the contact points were at the top or bottom of the capsule, since that may give you a wack ass result if you have a near collision near the center of the capsule.

Simply providing the contact point in the trace result is simpler (presumably?) and is actually the desired data.

(Sorry about the close/reopen. Misclick...)