Physics.raycast must return all objects along the ray

#1

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.
1 Like

#2

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

#3

@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.

2 Likes

#4

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

#5

+1

1 Like

#6

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.

0 Likes