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)!
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?
Unfortunately I cannot, as the rays Iām using arenāt guaranteed to have any collision objects on either endpoint.
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.
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.
ā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