Skip to content

Instantly share code, notes, and snippets.

@DemmyDemon
Created October 5, 2023 06:55
Show Gist options
  • Save DemmyDemon/fc060846ad1b476c6842b1cd3065afe3 to your computer and use it in GitHub Desktop.
Save DemmyDemon/fc060846ad1b476c6842b1cd3065afe3 to your computer and use it in GitHub Desktop.
Orbital camera
-- This code is ANCIENT, and probably contains natives that have been renamed.
-- It also contains references to functions not provided here.
-- Either way, it should illustrate how to orbit a camera around a target Ped.
function moveCamera()
if IsEntityAPed(targetPed) then
local targetCoords = nil
if IsPedInAnyVehicle(targetPed,false) then
local vehicle = GetVehiclePedIsIn(targetPed,false)
targetCoords = GetEntityCoords(vehicle)
elseif IsPedHuman(targetPed) then
targetCoords = GetWorldPositionOfEntityBone(targetPed,targetHeadIndex)
else
targetCoords = GetEntityCoords(targetPed)
end
local polarRadians = cameraPolarAngle * math.pi / 180.0
local azimuthRadians = cameraAzimuth * math.pi / 180.0
local cam = getCamera()
SetCamCoord(cam,
targetCoords.x + cameraRadius * (math.sin(azimuthRadians) * math.cos(polarRadians)),
targetCoords.y - cameraRadius * (math.sin(azimuthRadians) * math.sin(polarRadians)),
targetCoords.z - cameraRadius * math.cos(azimuthRadians)
)
PointCamAtCoord(cam,targetCoords)
end
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment