I wabted to check which object is topmost in certain x, y of screen. So I used this
function on_input(self, action_id, action)
if action_id == hash("mouse_left") then
physics.ray_cast(vmath.vector3(action.screen_x, action.screen_y, 1), vmath.vector3(action.screen_x, action.screen_y, -1), {hash("default")})
end
end
Resulting in game crashing with
Assertion failed: r.LengthSquared() > 0.0f, file c:\ci_slave\builds\engine-win32-master\build\engine\physics\src\box2d\Box2D/Collision/b2DynamicTree.h, line 232
That’s unfortunately not possible as the physics is 2D, so there is no z-component. Your ray will be squashed to (x, y, 0)-(x, y, 0), giving it a length of 0 and which removes its direction. You could do the collision through the means of a temporary shape you spawn for the sole purpose of doing the check (having a shape, e.g. sphere, also gives you added “radius” which is often useful for doing picking) and you could then check the z of the colliding objects.
That error message is really ugly though and should describe the situation better.
2 Likes