Type Function Library physics.* Return value The x and y of the reflected ray Revision 2018.3435 Keywords ray, raycast, casting, physics, collision, reflect, reflection See also physics.rayCast()
This function is used to reflect a vector as returned by physics.rayCast().
The reflected vector returned represents the direction of the reflection, and has a magnitude (length) of 1.
physics.reflectRay( fromX, fromY, hit )
Number. The starting x position of the ray.
Number. The starting y position of the ray.
local hits = physics.rayCast( 0, 0, 200, 300, "closest" ) if ( hits ) then -- There's at least one hit print( "Hit count: " .. tostring( #hits ) ) print( "The first object hit is: ", hits.object, " at position: ", hits.position.x, hits.position.y, " where the surface normal is: ", hits.normal.x, hits.normal.y ) local reflected_ray_direction_x, reflected_ray_direction_y = physics.reflectRay( 0, 0, hits ) print( "Reflected direction: ", reflected_ray_direction_x, reflected_ray_direction_y ) else -- No hits end