Skip to content

Feat: Add look-at target support to setCameraTarget & Fix #4915 - #5219

Open
MohabCodeX wants to merge 3 commits into
multitheftauto:masterfrom
MohabCodeX:feat/camera-target-lookat
Open

Feat: Add look-at target support to setCameraTarget & Fix #4915#5219
MohabCodeX wants to merge 3 commits into
multitheftauto:masterfrom
MohabCodeX:feat/camera-target-lookat

Conversation

@MohabCodeX

Copy link
Copy Markdown
Contributor

Summary

This pull request introduces comprehensive Look-At target support to setCameraTarget across both client and server sides, and additionally resolves Issue #4915 (camera rotation desynchronization on frozen peds) with a clean fix that prevents any camera lag or breaking changes.

1. Feature: Look-At Target Support in setCameraTarget

Previously, setCameraTarget only supported targeting an entity (or fixed coordinates via old client syntax), but could not dynamically orient the follow camera towards a specific 3D coordinate or another entity while maintaining free mouse orbiting.

Syntax Reference

Side Function Signature Description
Client setCameraTarget(targetElement) Snaps third-person camera to follow targetElement (Default)
Client setCameraTarget(targetElement, targetX, targetY, targetZ) (✨New) Follow targetElement while orienting camera towards (targetX, targetY, targetZ)
Client setCameraTarget(targetElement, targetLookAtElement) (✨New) Follow targetElement while orienting camera towards targetLookAtElement
Client setCameraTarget(targetX, targetY, targetZ) Orbit around coordinates (Legacy syntax preserved)
Server setCameraTarget(player, [targetElement = player]) Resets/targets camera on targetElement (Default)
Server setCameraTarget(player, targetElement, targetX, targetY, targetZ) (✨New) Synchronizes targetElement + 3D look-at coordinates via RPC
Server setCameraTarget(player, targetElement, targetLookAtElement) (✨New) Synchronizes targetElement + target look-at element via RPC
Server setCameraTarget(player, targetX, targetY, targetZ) (✨New Shorthand) 4-arg syntax to look at 3D coordinates
OOP player:setCameraTarget(...) Full OOP method support for all signatures

2. Practical Use Cases & Examples

Example 1: Mission / Tutorial - Point camera to a landmark or objective

-- Point the player's camera towards a bank vault or heist marker while allowing free mouse orbit
local vaultX, vaultY, vaultZ = 1450.5, -1020.3, 25.0

-- Client-side:
setCameraTarget(localPlayer, vaultX, vaultY, vaultZ)

-- Server-side:
setCameraTarget(player, vaultX, vaultY, vaultZ) -- Using new 4-arg shorthand
-- or:
player:setCameraTarget(vaultX, vaultY, vaultZ) -- Using OOP

Example 2: Dynamic Element Look-At (Focus on a suspect's vehicle or NPC)

-- When an NPC starts talking, snap the camera orientation towards that NPC
local bossPed = createPed(120, 1480.0, -1720.0, 13.5)

-- Client-side:
setCameraTarget(localPlayer, bossPed)

-- Server-side:
setCameraTarget(player, player, bossPed)

Example 3: Spectator System (Spectate a teammate while orienting towards the bomb site)

-- Spectate teammate while pointing the camera towards the bomb site
local teammate = getPlayerFromName("Player2")
local bombX, bombY, bombZ = 2000.0, -1500.0, 15.0

-- Client-side:
setCameraTarget(teammate, bombX, bombY, bombZ)

-- Server-side:
setCameraTarget(adminPlayer, teammate, bombX, bombY, bombZ)

Example 4: Cutscene / Respawn Recovery (Default Reset)

-- Restores camera back to local player after a cutscene or respawn
-- Client-side:
setCameraTarget(localPlayer)

-- Server-side:
setCameraTarget(player, player)

Note

And more in the testing script

3. Bug Fix: Issue #4915 (Camera Rotation Desync on Frozen Peds)

  • Problem: When a frozen player/ped was rotated, the frozen state retained the old rotation, causing setCameraTarget to fail to snap the camera behind the player.
  • Fix: Synchronize the rotation in the frozen state so setCameraTarget instantly and accurately aligns behind the player without any lag or gameplay disruption.

4. Testing & Verification

camera_target_test.zip

  • Exact Issue setCameraTarget does not sync camera rotation with ped rotation in some cases (1.7 regression) #4915 Reproduction:
    • Tested with the exact reporter script (setElementFrozen -> server setElementDimension / setElementInterior / setElementRotation -> setCameraTarget(client)).
    • Confirmed instant and exact camera synchronization behind the ped (PASS).
  • Look-At Testing:
    • Tested client and server random 3D coordinate targeting, custom coordinates, and dynamic vehicle/ped look-at targets.
    • Tested 4-arg server shorthand and OOP methods.
  • Backward Compatibility:
    • Tested default setCameraTarget(localPlayer) and orbit mode setCameraTarget(x, y, z) ensuring 100% backward compatibility.

@MohabCodeX

Copy link
Copy Markdown
Contributor Author

Partially fixed #4074

@FileEX FileEX added enhancement New feature or request bugfix Solution to a bug of any kind labels Aug 21, 2026
@FileEX

FileEX commented Aug 21, 2026

Copy link
Copy Markdown
Member

As for fixing the bug itself, is PR #5013 sufficient?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

bugfix Solution to a bug of any kind enhancement New feature or request

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants