Jump to content

Camera Functions


OffRoader23

Recommended Posts

I've been looking at the camera functions and wanting to know if theres a way to make the camera an element so it can be attach to a vehicle at any x/y/z position I want. Is this possible with this version of MTA? I know I could run a timer to move the camera to the player every 50ms, but the delay of 50ms is way too long IMO, and makes the camera very jerky. I want to do this to make like, in vehicle cameras and anything like that. The camera commands don't seem to be working for me at all? I was just testing them and it would NOT change my camera, and my console returned no errors.

function dropCamera (player) 
    local x, y, z = getElementPosition ( player ) 
    setCameraMode ( player, "player" ) 
    setCameraPosition ( player, x, y, z ) 
end 
addCommandHandler ( "dropcamera", dropCamera) 

Just supposed to drop the camera in place, and follow the player, but it doesn't work on foot or in vehicle, and returns no console errors.

Link to comment

this is a simple script that places the camera above the player (GTA2 style)

local root = getRootElement() 
local localPlayer = getLocalPlayer () 
local update = false 
  
function updateCameraPos() 
    local x, y, z = getElementPosition ( localPlayer ) 
        setCameraPosition ( x, y-1, z + 30 ) 
        setCameraLookAt ( x, y, z ) 
    end 
end 
  
  
function changeCamera() 
    if ( update == false ) then 
        update = true 
        toggleCameraFixedMode ( true ) 
        addEventHandler ( "onClientRender", root, updateCameraPos ) 
    else 
        update = false 
        toggleCameraFixedMode ( false ) 
        removeEventHandler ( "onClientRender", root, updateCameraPos ) 
    end 
end 
  
addCommandHandler ( "cam", changeCamera ) 

if you wanna know what I mean by 'jerky' change this line to

setCameraPosition ( x, y-1, z + 3 ) 

Link to comment

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...