Raycast response when nothing is hit (DEF-1101) (SOLVED)

I would like to get a ray_cast_response message even when nothing is hit. As it is now, the only way of knowing a path is clear of obstacles is by a reverse ray (destination->source) and that is not always possible

We have an issue reported for this, Iā€™ll talk to the team trying to increase the priority for it (canā€™t promise anything)! :slight_smile:

2 Likes

Is there any way that this can get implemented in the near future? Iā€™m trying to detect the specific action of nothing getting hit by a raycast, and itā€™s difficult to base that on the lack of a ray_cast message, the timing between the physics update and update(dt) seems to not match up perfectly. I thought the physics system was synced to the update loop but Iā€™m getting some behavior that seems to suggest otherwise. Is it?

Could you solve it as I did - with a reversed raycast?

2 Likes

Unfortunately I cannot, as the rays Iā€™m using arenā€™t guaranteed to have any collision objects on either endpoint.

1 Like

I donā€™t understand the inconsistency you describe about timing, could you elaborate that?

All raycasts requested from a script-update, will be handled by the physics update (which happens in the same frame, slightly after the scripts have been updated). This means that this very annoying workaround will work perfectly for each case:

function update(self, dt)
  ...
  if self.waiting_for_raycast then
    self.waiting_for_raycast = false
    -- handle missing ray casts
  end
  if my_cast_condition then
    self.waiting_for_raycast = true
    -- request ray cast
  end
end

function on_message(....)
  if raycast_etc then
    self.waiting_for_raycast = false
    -- take action
  end
end

Sorry for being too lazy to type out all the code, hope it makes sense anyway.

After trying this code, Iā€™m guessing that Iā€™m just doing something wrong and itā€™s not an engine issue:

function update(self, dt)
  ...

  -- respond to lack of a raycast response
  if self.raycast_await then print("airborne") end

  -- raycast
  physics.ray_cast(go.get_position() + vmath.vector3(0, -4, 0), go.get_position() + vmath.vector3(0, -8, 0), {hash("tile")})
  self.raycast_await = true
end

function on_message(self, message_id, message, sender)
  ...

  if message_id == hash("ray_cast_response") then
    self.raycast_await = false
  end
end

This code is attached to the ā€˜playerā€™ object, and when I jump high enough that there shouldnā€™t be any tiles 12 units below the player, even taking into account the camera scaling, I still get a constant stream of ā€œairborneā€ messages. I thought the issue might be the background ā€˜wallā€™ since itā€™s full of the same tile objects the ground is made of, but with the colliders disabled, but even when I moved to an area without a background wall the message is constantly repeated.

Any idea what the issue might be here? Iā€™m thinking it could be a problem with z values, as the calling object has a different z value then the tiles - in the past I think I manually set the z of the ray points and it not fixing the issue, but I found another solution and discarded that code.

1 Like

Is there is any chance in near future, that we can do a raycast and get result immediately? I need to do a series of raycasts (in same frame) where next raycast depends of previous results.

2 Likes

ā€œnothing-is-hitā€ response or immediate raycast results is still will be a very welcome addition.

Could you possibly put some objects around the outside of the scene and if a ray hits that object but no other objects, it returns a ā€œno hitsā€ raycast?

Ray cast miss message added to Defold 1.2.115

4 Likes