Commits

Bart van Strien committed 7246afe

Return nil if the raycasts don't hit anything (issue #335)

Comments (0)

Files changed (2)

src/modules/physics/box2d/Fixture.cpp

 		input.maxFraction = maxFraction;
 		b2Transform transform(b2Vec2(x, y), b2Rot(r));
 		b2RayCastOutput output;
-		fixture->RayCast(&output, input, childIndex);
+		if (!fixture->RayCast(&output, input, childIndex))
+			return 0; // Nothing hit.
 		lua_pushnumber(L, Physics::scaleUp(output.normal.x));
 		lua_pushnumber(L, Physics::scaleUp(output.normal.y));
 		lua_pushnumber(L, output.fraction);

src/modules/physics/box2d/Shape.cpp

 		input.maxFraction = maxFraction;
 		b2Transform transform(b2Vec2(x, y), b2Rot(r));
 		b2RayCastOutput output;
-		shape->RayCast(&output, input, transform, childIndex);
+		if (!shape->RayCast(&output, input, transform, childIndex))
+			return 0; // No hit.
 		lua_pushnumber(L, Physics::scaleUp(output.normal.x));
 		lua_pushnumber(L, Physics::scaleUp(output.normal.y));
 		lua_pushnumber(L, output.fraction);