local function RotationToDirection(rotation) local adjustedRotation = { x = (math.pi / 180) * rotation.x, y = (math.pi / 180) * rotation.y, z = (math.pi / 180) * rotation.z } local direction = { x = -math.sin(adjustedRotation.z) * math.abs(math.cos(adjustedRotation.x)), y = math.cos(adjustedRotation.z) * math.abs(math.cos(adjustedRotation.x)), z = math.sin(adjustedRotation.x) } return direction end local function RayCastGamePlayCamera(distance) local currentRenderingCam = false if not IsGameplayCamRendering() then currentRenderingCam = GetRenderingCam() end local cameraRotation = not currentRenderingCam and GetGameplayCamRot() or GetCamRot(currentRenderingCam, 2) local cameraCoord = not currentRenderingCam and GetGameplayCamCoord() or GetCamCoord(currentRenderingCam) local direction = RotationToDirection(cameraRotation) local destination = { x = cameraCoord.x + direction.x * distance, y = cameraCoord.y + direction.y * distance, z = cameraCoord.z + direction.z * distance } local _, hit, endCoords, surfaceNormal, entityHit = GetShapeTestResult(StartShapeTestRay(cameraCoord.x, cameraCoord.y, cameraCoord.z, destination.x, destination.y, destination.z, -1, PlayerPedId(), 0)) return _, hit, endCoords, surfaceNormal, entityHit end function ps.raycast() local _, hit, endCoords, surfaceNormal, entityHit = RayCastGamePlayCamera(1000.0) return hit, endCoords, surfaceNormal, entityHit end