Replies: 1 comment 1 reply
-
On reviewing the source code, nothing is standing out to me immediately in the collision shapes themselves that would preclude an internal raycast from providing surface results. However, this is all currently bypassed in the godot space 3D file ln 154 which either skips the shape entirely or simply returns a zeroized result. I'm curious if we simply modify the check to allow the raycast to continue if 'hit_back_faces=true` whether we would obtain my desired result. I may try and build it this weekend and see what happens |
Beta Was this translation helpful? Give feedback.
1 reply
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
-
Describe the project you are working on
A 3D fps game with a heavy focus on stealth and perception
Describe the problem or limitation you are having in your project
As part of my observation system, I need to determine both what objects are in the way of line-of-sight between two points, as well as how long those objects are in the line-of-sight path. While obtaining a list of objects is relatively trivial (continuous addition of objects to raycast exception lists until none are left), obtaining the lengths of the objects along the line is not as simple.
Describe the feature / enhancement and how it helps to overcome the problem or limitation
The raycast
hit_back_faces
option currently works only on concave polygon shapes with back face enabled. However, it would be extremely useful if we could cast a ray from inside an object or area, and have it directly provide the collision point to the surface. This should hopefully be a single raycast call.Currently, to find object lengths, I use a raycast with
hit_from_inside
on and iteratively step forward with small increments until outside the object, then point the raycast back at the object to find the external surface. Depending on scene density and the number of observers, this can result in a significant number of raycasts.Describe how your proposal will work, with code, pseudo-code, mock-ups, and/or diagrams
Build a raycast query with the following specifications:
query.from
: A point inside the area/objectquery.to
: A point outside the area/objectquery.hit_from_inside = true
query.hit_back_faces = true
: Allow hitting the surface from inside the area/object. Iffalse
, it should return the same results as a current raycast (zero-ized vectors ifhit_from_inside
is true)The result position would then contain the intersection point on the object/area surface, and the collision normal would be inverted to point inwards towards the object
How it works in code:
The simplest and most non-intrusive method is to modify the GodotPhysicsDirectSpaceState3D::intersect_ray function to do the following:
hit_back_faces
ANDhit_from_inside
aretrue
:I've got a version of this here
Notes:
For a collision object with multiple collision shapes, this will return the closest surface point for all shapes.
For intersecting collision objects, the raycast may be internal to one however it will report the other as the collision since it is closer to the raycast origin. This seems reasonable to me as turning on
hit_back_faces
is an indication that the user views the collision shapes as surfaces rather than volumes. (To that end, would it be better to requirehit_from_inside=false
to produce this behavior as a way to further enforce the volume vs surface mentality?)If this enhancement will not be used often, can it be worked around with a few lines of script?
Technically yes, but with potentially significant performance impacts that can only be mitigated with reduced fidelity.
Beta Was this translation helpful? Give feedback.
All reactions