godotengine / godot-proposals

Godot Improvement Proposals (GIPs)
MIT License
1.07k stars 69 forks source link

Add PunchThrough RayCast #2616

Open invisiblesun opened 3 years ago

invisiblesun commented 3 years ago

Describe the project you are working on

Not specific to a project.

Describe the problem or limitation you are having in your project

In some games, there may be a desire for weapons or "sight" to have 'punch-through', that is, that a projectile pierces the target and is intended to effect something beyond it. Or some Hero Protagonist has x-ray vision. Or lighting effects added through several solids (as with a laser beam say).

RayCasts are generally an option but due to their primary function, only 'see' the first thing they hit.

Describe the feature / enhancement and how it helps to overcome the problem or limitation

The proposal here would to have a x-ray-cast if you will that collects collisions from beginning to end over the length of the cast ray.

Describe how your proposal will work, with code, pseudo-code, mock-ups, and/or diagrams

x-ray-cast might proceed just as ray-cast but continue over its cast_to length

If this enhancement will not be used often, can it be worked around with a few lines of script?

RayCasts can be called sequentially, by adding collided objects to the ignore list. It works but incurs an overhead of repeated calls or waits over physics_process frames.

Is there a reason why this should be core and not an add-on in the asset library?

It would need to be core as the work arounds are inefficient, by adding collision objects to the ignore list and having to repeat calls to intersect_ray or by using RayCast. I could see it as an asset library add-on but that add on would seem to need the internals of the physics servers.

clayjohn commented 3 years ago

Doesn't intersect_ray already provide a dictionary of all objects that intersect with the given ray?

invisiblesun commented 3 years ago

The dictionary represents a single collision. intersect_shape() and collide_shape() returns an array of dictionaries.

One could argue that using these with a pencil thin shape (like capsule) would do the trick, but my experience with bullet is the reported contacts are oriented towards colliding with contacts closest to the surface of the collision shape, this results in contacts reported on the ‘far’ side of the object you might want instead to ’see’ the near side

On Apr 16, 2021, at 9:59 AM, Clay John @.***> wrote:

Doesn't intersect_ray https://docs.godotengine.org/en/stable/classes/class_physicsdirectspacestate.html#class-physicsdirectspacestate-method-intersect-ray already provide a dictionary of all objects that intersect with the given ray?

— You are receiving this because you authored the thread. Reply to this email directly, view it on GitHub https://github.com/godotengine/godot-proposals/issues/2616#issuecomment-821311304, or unsubscribe https://github.com/notifications/unsubscribe-auth/AM7FY63NOGYYGFOJOP5LF6TTJBUHNANCNFSM43B3SXCQ.

ev1313 commented 2 months ago

Instead of adding new functionality for the "far" side, you can just reverse the order of the begin/end of the ray. This should work if all meshes are convex (or you don't care about the concave corner case).