Jump to content

Camera Functions


OffRoader23

Recommended Posts

Posted

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.

[NR]OffRoader23 - Leader of [NR] Gaming Clan

Server: 194.187.212.136:10000

Free Roam Chaos, with MANY commands, a DM arena, and a great team system.

blue2.png

Posted

You want to do it client side, with the onClientRender event, toggleCameraFixedMode and setCameraPosition and setCameraLookAt.

Posted

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 ) 

:d::i::s::g::r::a::c::e:

norby89.png

Posted

Woah, interesting script. So this updates the camera onClientRender, as in every frame ?

"The humble beet is the answer to all riddles." - Rolf

Posted
Yes, and the jerkiness is an issue with the camera functions not being set in the same frame, it might be fixed in the next version.

*pees in his pants* T_T

:d::i::s::g::r::a::c::e:

norby89.png

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...