Created
October 5, 2023 06:55
-
-
Save DemmyDemon/fc060846ad1b476c6842b1cd3065afe3 to your computer and use it in GitHub Desktop.
Orbital camera
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
-- 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