Physics.raycast must return all objects along the ray (#4710) (SOLVED)

Raycast should be able to:

  • return any (arbitrary) object along the ray
  • return all objects
  • return closest object
    We have only the last option now. This is not enough.
4 Likes

Is this not possible now? Multiple raycast collisions work in Box2D: https://www.iforce2d.net/b2dtut/raycasting

Maybe the Defold implementation is different.

Related: Raycast with several results

1 Like

@totebo I think what @dmitriy wants is to use a custom collision filter object, to make it possible to discard or collect any results along the ray cast.

A useful feature, let’s put it on the backlog.

4 Likes

I want something like this:
physics.raycast(from, to, groups, raycast_type)

local hit = physics.raycast(from, to, groups, physics.ANY _HIT)
Returns the first collisionobject discovered that intersects the ray. This may be any(arbitrary) object along the ray. If no object intersects the ray, returns nil.

local hits = physics.raycast(from, to, groups, physics.ALL _HITS)
Returns (in a table array) all the collisionobjects that intersects a ray. May return nil or empty table if no hit at all, I’m not sure what exactly.

local hit = physics.raycast(from, to, groups, physics.CLOSEST _HIT)
Returns the closest collisionobject that intersects the ray. If no object intersects the ray, returns nil. This is what we have now.

1 Like

+1

1 Like

The inability to do what I am describing here makes some game mechanics (shoot, pierce, hit multiple targets) difficult, inefficient and not reliable to implement.

Just a friendly reminder that this feature very useful and deserves higher priority.

3 Likes

Make raycasts great again. Give them PENETRATION POTENCY.

I’ve added this as an investigation for our current sprint. No promises though!

2 Likes

Let’s raise this thread every month.

2 Likes

Let’s raise this thread every month.

2 Likes

The code is now in review, and should land in the 1.2.170 BETA on monday.

5 Likes

Sometimes it pays off to be a thorn in the side of an engine dev!

1 Like

Cool! This will greatly simplify cases that are VERY difficult to solve in another way.

Solved in 1.2.170

1 Like