Add new Traceray natives #754
Does something like the following make more sense to be consistent with the other TR natives:
This is making the assumption that after you've clipped the ray you'll always be returning false, is this assumption correct?
When is the
Only other thing I would like to see is replacing the boolean
(I had a different post previously but realized something at the last minute and have revised it)
I think the best solution is to call
This also makes the mask parameter make more sense.
I definitely think ClipRayToEntity should be available directly. I can envision scenarios where you have a known entity and just want to clip a ray to it, and having to go through EnumerateEntities would be odd.
At first I was against calling ClipRayToEntity automatically because it could potentially be wasteful to do so, but if we want to allow calling ClipRayToEntity on its own without it being tied to another TR_ call, then ClipRayToEntity needs its own ray parameters which would make it very awkward to manually call within or in response to the EnumerateEntities enumerator.
Edit: Also need to make sure ClipRayToEntity causes TR_DidHit to return true.
Clipping the ray doesn't always mean that you want to stop enumerating. The condition for stopping the enumerating could be dependent on the results of ClipRayToEntity (or something else entirely).
This depends on the use case. Using different masks on entities could give different results depending on where it hits them. For example, say I wanted to clip the ray to a players bounding box rather than it's hitbox, I could use MASK_PLAYERSOLID for that. I tested this out myself using this code. Here's an image showcasing it as well (red hits hitbox, green hits bbox): https://i.imgur.com/HjNZqEy.jpg
Do you mean making an enum specifically for this? I only made it a boolean since the function it calls also uses a bool so I thought that would be the most straightforward way to do it.
When the clipping doesn't hit anything, the trace result fraction is set to 1.0 and DidHit returns false
Also I wasn't sure about my ClipRayToEntity implementation, since it creates a new trace result out of the global ray. When you want to use the global trace result you pass in INVALID_HANDLE, or pass in a handle and it gets filled with a new trace result. Should I change this behaviour to work like the other TR functions with a regular/Ex version?
I've pushed another commit that seperates ClipRayToEntity into 2 groups of natives:
This way the ClipRayToEntity function isn't tied down to EnumerateEntities and can also be used by itself.
Here is the same example plugin I posted above but updated to use the new natives: https://pastebin.com/CB5uJFLz
That implementation looks solid in my opinion.
Just to clarify why SildyBat went with two versions of
At a minimum, it makes sense to have a version of