I’m trying to do what I’d do in other engines, doing a raycast across my 2D plane (z = 0) to see if I hit any Game Objects on that plane. But when I do the raycast dmengine is crashing, so I guess I am doing something wrong. I get this error message:
Assertion failed: (r.LengthSquared() > 0.0f), function RayCast, file …/src/box2d/Box2D/Collision/b2DynamicTree.h, line 232.
My code is very simple, just doing this:
function init(self)
msg.post(".", "acquire_input_focus")
self.raycast_collision_groups = { hash("group1") }
end
function on_message(self, message_id, message, sender)
if message_id == hash("ray_cast_response") then
-- act on the hit
end
end
function on_input(self, action_id, action)
if action_id == hash("touch") and action.pressed then
physics.ray_cast(vmath.vector3(action.x, action.y, 10), vmath.vector3(action.x, action.y, -10), self.raycast_collision_groups)
end
end
Does anyone have any idea what is wrong here? I thought a raycast for z = 10 to z = -10 would cross the plane and the message would let me know if any Game Objects were hit.
I do have one Game Object in the scene with a collision component in group “group1”.