physics.reflectRay()

类型 函数
physics.*
返回值 反射射线的 xy
修订 版本 2024.3703
关键词 射线, 光线投射, 投射, 物理, 碰撞, 反射
另请参阅 physics.rayCast()

概述

此函数用于反射 physics.rayCast() 返回的向量。

返回的反射向量表示反射方向,其大小(长度)为 1。

语法

physics.reflectRay( fromX, fromY, hit )
fromX (必需)

数字. 射线的起始 x 位置。

fromY (必需)

数字. 射线的起始 y 位置。

hit (必需)

. physics.rayCast() 返回的 hits 数组中的一项。

示例

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[1].object, " at position: ", hits[1].position.x, hits[1].position.y, " where the surface normal is: ", hits[1].normal.x, hits[1].normal.y )

    local reflected_ray_direction_x, reflected_ray_direction_y = physics.reflectRay( 0, 0, hits[1] )
    print( "Reflected direction: ", reflected_ray_direction_x, reflected_ray_direction_y )
    
else
    -- No hits
end