跳至正文
版本:最新版 - a1.156.0 ⚖️

🔍 跟踪

Failed to load class '跟踪' (StaticClass) data.

🎒 示例​

Client/Index.lua
-- Gets the local player
local local_player = Client.GetLocalPlayer()

-- Gets the camera rotation and location
local camera_rotation = local_player:GetCameraRotation()
local start_location = local_player:GetCameraLocation()

-- Calculates the direction vector based on the camera rotation
local direction = camera_rotation:GetForwardVector()

-- Calculates the end location of the trace
-- (start location + 20000 units in the direction of the camera)
local end_location = start_location + direction * 20000

-- Filter everything we want to trace (e.g. WorldStatic, WorldDynamic, PhysicsBody, Vehicle)
local collision_trace = CollisionChannel.WorldStatic | CollisionChannel.WorldDynamic | CollisionChannel.PhysicsBody | CollisionChannel.Vehicle

-- Define the parameters for the trace
-- TraceMode.TraceOnlyVisibility means we only want to trace against objects that are visible
-- TraceMode.DrawDebug means we want to draw debug lines for the trace for visualization
-- TraceMode.TraceComplex means we want to trace against complex collision shapes
-- TraceMode.ReturnEntity means we want to return the entity that was hit by the trace
local trace_mode = TraceMode.TraceOnlyVisibility | TraceMode.DrawDebug | TraceMode.TraceComplex | TraceMode.ReturnEntity

-- Do the trace
local trace_result = Trace.LineSingle(start_location, end_location, collision_trace, trace_mode)

-- If the trace was successful
if (trace_result.Success) then
-- And we got an entity, print the name of the collided entity, otherwise just print the location
if (trace_result.Entity) then
Console.Log("Trace Success! Entity: " .. tostring(trace_result.Entity) .. ". Location: " .. tostring(trace_result.Location))
else
Console.Log("Trace Success! Location: " .. tostring(trace_result.Location))
end
else
-- If the trace was not successful, print a message
Console.Log("Failed to trace")
end

🗿 静态函数​

Failed to load class '跟踪' (StaticClass) data.

🚀 事件​

Failed to load class '跟踪' (StaticClass) data.