Jump to content

question about camera mode and position


Recommended Posts

hi all :D

i have just been browsing the wiki and i came across camera mode and camera position

is it possible to make the camera pan round ( watch someone do a jump / crash )

i assume i would have to set camera start position and then use settimer to move it so u can watch the player from a distance but just wanted to be sure

thanx for any replys

another thought is there a zoom ability or would i just need to move camera closer

Link to comment

sorry to sound dumb 50p but what would that do

my idea is to make a thrill cam like in stuntman. when you do a big jump or something like that it changes camera angle so you get a better look at the jump and it looks more dramatic

do i need to do this client side ( so as not to create lag or something )

or do u mean i should use on client render to update the camera position as the player moves

i was also considering slowing game speed during the jump but not sure if i can do that for just one player. not to worry to much about the slowdown thing as i have just this second thought of it and havent really looked to see if it can be done

Link to comment

There's no functions to animate the postion/angle of the camera so you need to do it yourself. For this to be smooth it needs to be done each frame - hence it needs to be client side. If the server was to issue client camera position/angle updates over time, they wouldn't be smooth (due to lag). So you need to write something that's hooked to the client renderer or a short period repeating timer - although I think the former would be better.

Link to comment

i have just tried this but no camera change and no errors

could anyone give me an idea where im wrong :D

server side

function docam ( player, command ) 
   triggerClientEvent ( player, "thrillcam", getRootElement() ) 
   outputChatBox ( "now" ) 
end 
  
addCommandHandler ( "camfun", docam ) 

clientside

function thrillcam ( theplayer, command ) 
   local player = getLocalPlayer ( player ) 
   local x,y,z = getElementPosition ( player ) 
   setCameraMode ( player, fixed ) 
   setTimer ( setCameraPosition, 10, 1, player, x + 10, y + 10, z + 10 ) 
   setTimer ( setCameraLookAt, 10, 1, player, x, y, z ) 
   setTimer ( setCameraMode, 3000, 1, player, player ) 
end 
  
addEvent ( "onThrillcam", true ) 
addEventHandler ( "onThrillcam", getRootElement(), thrillcam ) 

at the moment im just trying to understand the functions and ill worry about trying to move it after

thanx for l :roll: kin

Link to comment

Try:

function thrillcam ( theplayer, command ) 
   local player = getLocalPlayer () 
   local x,y,z = getElementPosition ( player ) 
   setCameraMode ( player, "fixed" ) 
   setTimer ( setCameraPosition, 100, 1, player, x + 10, y + 10, z + 10 ) 
   setTimer ( setCameraLookAt, 100, 1, player, x, y, z ) 
   setTimer ( setCameraMode, 3000, 1, player, "player" ) 
end 
  

Edit: setCameraMode() is server-only. You'll need toggleCameraFixedMode() maybe ? (I haven't done this kind of thing).

Link to comment

thanx for the reply TMA

i was looking at the wiki again and thought this might work but still no change and no errors

server side

function docam ( player, command ) 
   setCameraMode ( player, fixed ) 
   triggerClientEvent ( player, "thrillcam", getRootElement() ) 
   outputChatBox ( "now" ) 
end 

addCommandHandler ( "camfun", docam )  

clientside

function thrillcam ( theplayer, command ) 
   local x,y,z = getElementPosition ( getLocalPlayer() ) 
   setCameraPosition ( x + 10, y + 10, z + 10 ) 
   setCameraLookAt ( x, y, z ) 
end 
  
addEvent ( "onThrillcam", true ) 
addEventHandler ( "onThrillcam", getRootElement(), thrillcam ) 

i was wondering when i do the triggerClientEvent does it know where the function in the client side script is. like do i have to tell it where it is in the xml file or anything like that

EDIT ::: now tried this but same result. just wondering if im getting any closer

server side

function docam ( player, command ) 
   triggerClientEvent ( player, "thrillcam", getRootElement() ) 
   outputChatBox ( "now" ) 
end 
  
addCommandHandler ( "camfun", docam ) 

client side

function thrillcam ( theplayer ) 
   local whatusee = getLoclaPlayer () 
   local x,y,z = getElementPosition ( whatusee ) 
   toggleCameraFixedMode ( whatusee, true ) 
   setTimer ( setCameraPosition, 10, 1, whatusee, x + 10, y + 10, z + 10 ) 
   setTimer ( setCameraTarget, 10, 1, whatusee, whatusee ) 
   setTimer ( toggleCameraFixedMode, 3000, 1, false ) 
end 
  
addEvent ( "onThrillcam", true ) 
addEventHandler ( "onThrillcam", getRootElement(), thrillcam ) 

if i try putting setCameraMode in the server function then it doesnt do the chatbox message. all the other ways i at least got the message

Link to comment

triggerClientEvent ( player, "thrillcam", getRootElement() ) 

You should get an error. Don't you get any errors? Login as an admin an type "debugscript 3" in console or "/debugscript 3". You should get a complaint about trying to trigger client-side event that was not added. You've got "onThrillcam" event, but you try to trigger "thrillcam". It's really important that you know the difference between function and event. You can't call client-side function from server-side script.

Link to comment

thanx for that 50P i was wondering how to use that debug script thing its very handy

i have tried using this code but it gives me an error in the client side script in line 2 attempt to call getLocalPlayer a nil value

server side

function docam ( player, command ) 
  triggerClientEvent ( player, "thrillcam", getRootElement() ) 
  outputChatBox ( "now" ) 
end 
  
addCommandHandler ( "camfun", docam ) 

client side

function thrillcam ( theplayer ) 
   local whatusee = getLoclaPlayer ( theplayer ) 
   local x,y,z = getElementPosition ( whatusee ) 
   toggleCameraFixedMode ( whatusee, true ) 
   setTimer ( setCameraPosition, 10, 1, whatusee, x + 10, y + 10, z + 10 ) 
   setTimer ( setCameraTarget, 10, 1, whatusee, whatusee ) 
   setTimer ( toggleCameraFixedMode, 3000, 1, false ) 
end 
  
addEvent ( "thrillcam", true ) 
addEventHandler ( "thrillcam", getRootElement(), thrillcam ) 

thanx for any advice :D

Link to comment

You REALLY have to pay attention to the name of functions, variable, etc. Lua is also case-sensitive.

You get that error because you try to use a function that doesn't exist, getLoclaPlayer ( theplayer ). This function doesn't require any arguments because that wouldn't be logical... Try to "get local player of player"? Use getLocalPlayer() only.

Link to comment

thanx a lot 50P :D:D

ok now trying it like this ( think i got rid of all the typeos )

with the debug running i get no errors but still doesnt work.

i have another script ( not written by me ) that detects when a player enters a collision sphere and then fires projectile at them and it calls a client side function ( to create the projectile ) in the same way this does so i thought it would work. is it not working because the server side script that calls the client side function is a player command instead of a hit collision sphere event.

im not totally sure what u meant when u said

It's really important that you know the difference between function and event. You can't call client-side function from server-side script.

but heres the script anyway

server side

function docam ( player, command ) 
  triggerClientEvent ( player, "thrillcam", getRootElement() ) 
  outputChatBox ( "now" ) 
end 
  
addCommandHandler ( "camfun", docam )  

client side

function thrillcam ( theplayer ) 
   local whatusee = getLocalPlayer () 
   local x,y,z = getElementPosition ( whatusee ) 
   toggleCameraFixedMode ( whatusee, true ) 
   setTimer ( setCameraPosition, 10, 1, whatusee, x + 10, y + 10, z + 10 ) 
   setTimer ( setCameraTarget, 10, 1, whatusee, whatusee ) 
   setTimer ( toggleCameraFixedMode, 3000, 1, false ) 
end 
  
addEvent ( "thrillcam", true ) 
addEventHandler ( "thrillcam", getRootElement(), thrillcam ) 

Link to comment

looking at the wiki it said i can use addCommandHandler client side so i have tried to run this as client side only but still no camera change and no error

function thrillcam ( theplayer ) 
   local whatusee = getLocalPlayer () 
   local x,y,z = getElementPosition ( whatusee ) 
   toggleCameraFixedMode ( whatusee, true ) 
   setTimer ( setCameraPosition, 10, 1, whatusee, x + 10, y + 10, z + 10 ) 
   setTimer ( setCameraTarget, 10, 1, whatusee, whatusee ) 
   setTimer ( toggleCameraFixedMode, 3000, 1, false ) 
   outputChatBox ( "go" ) 
end 
  
addCommandHandler ( "funcam", thrillcam ) 

EDIT :::

i have managed to find a script that does what i want it to on another thread but it did say it gets very jumpy ( they were right )

thanx for all the help :D

Link to comment

i am now trying to do it like this but it gives me nothing and as far as i can see it should work ( no errors, no object, no message )

server side

thrillcammarker = createCollisionSphere ( -735, 790, -200, 5 ) 
  
function setcam ( player ) 
   setElementPosition ( thrillcammarker, -735, 790, 14 ) 
   createObject ( 16303, -740.47650146484, 700.71752929688, 13.409936904907, 359.5, 0, 350.5 ) 
   outputChatBox ( "1" ) 
end 
  
function thrillcam ( element ) 
   triggerClientEvent ( element, "onchangeCamera", getRootElement () ) 
   outputChatBox ( "2" ) 
end 
  
addCommandHandler ( "startcamera", setcam ) 
addEventHandler ( "onColShapeHit", thrillcammarker, thrillcam ) 

client side

local root = getRootElement() 
local localPlayer = getLocalPlayer () 
local update = false 
  
function updateCameraPos() 
   local x, y, z = getElementPosition ( localPlayer ) 
   setCameraLookAt ( x, y, z ) 
    
end 
   
   
function changeCamera() 
   if ( update == false ) then 
     update = true 
     toggleCameraFixedMode ( true ) 
     setCameraPosition ( -681, 662, 18 ) 
     addEventHandler ( "onClientRender", root, updateCameraPos ) 
   else 
     update = false 
     toggleCameraFixedMode ( false ) 
     removeEventHandler ( "onClientRender", root, updateCameraPos ) 
   end 
end 
   
addEvent ( "onchangeCamera", true ) 
addEventHandler ( "onchangeCamera", getRootElement (), changeCamera ) 

i know the basic client side script works if its used with a command handler but i cant see what ive done wrong with the server side. i think it is probably something to do with the trigger client event but from what i can tell from the other scripts i use this should be ok. what i want to do is create a ramp with a collision sphere on it so that when you jump off the ramp it switches the camera to a fixed point and follows the car while staying in one place. i am also going to put another collision sphere to switch back to normal camera or maybe just a timer.

thanx for any help :D

Link to comment

Triple post! You should be warned...

1. Do you read wiki? createCollisionSphere? (createColSphere)

2. You createObject in command only, so how do you expect it to work in any other way?

Everything seems fine but...

- change the createCollisionSphe to createColSphere

- createObject when resource starts or with colshape

... and it should be ok.

Link to comment

sorry about triple post 50P ( wont happen again )

thank u very much :D

hope somebody sees this :D:D

i have now got the script working ( THANK U ALL ) but the camera only works every other time player hits collision sphere and the first time it sets camera to very strange position ( farm i think ) and u cant see player. it is a bit jumpy but its still pretty cool but was wondering if i had done something wrong to cause it not to work every time you hit collision sphere.

server side

thrillcammarker = createColSphere ( -724, 693, -200, 5 ) 
  
function setcam ( element ) 
   setElementPosition ( thrillcammarker, -724, 693, 20 ) 
   outputChatBox ( "1" ) 
end 
  
function thrillcam ( element ) 
   triggerClientEvent ( element, "onchangeCamera", getRootElement () ) 
   setTimer ( setElementPosition, 1000, 1, thrillcammarker, -724, 693, -200 ) 
   outputChatBox ( "2" ) 
end 
  
addCommandHandler ( "startcamera", setcam ) 
addEventHandler ( "onColShapeHit", thrillcammarker, thrillcam ) 

client side

local root = getRootElement() 
local localPlayer = getLocalPlayer () 
local update = false 
  
function updateCameraPos() 
   local x, y, z = getElementPosition ( localPlayer ) 
   setCameraLookAt ( x, y, z ) 
    
end 
   
   
function changeCamera() 
   if ( update == false ) then 
     update = true 
     toggleCameraFixedMode ( true ) 
     setCameraPosition ( -681, 662, 18 ) 
     addEventHandler ( "onClientRender", root, updateCameraPos ) 
     setTimer ( toggleCameraFixedMode, 3000, 1, false ) 
   else 
     update = false 
     toggleCameraFixedMode ( false ) 
     removeEventHandler ( "onClientRender", root, updateCameraPos ) 
   end 
end 
   
addEvent ( "onchangeCamera", true ) 
addEventHandler ( "onchangeCamera", getRootElement (), changeCamera ) 

i put the timer to move the sphere back to the original position in hoping that if i had to restart the function with the startcamera command it would stop the weird behavior but it did not help. really not sure if this is my fault or not in this one. it looks ok to me and it does work ( sort of ) but i dont know much about scripting yet so any ideas appreciated thanx.

THANX AGAIN :D:D:D

Link to comment
  • 2 months later...
what bugs does it have?

All kinds of...

-Falling through the ground sometimes

-Getting out of vehicles suddenly and THEN falling sometimes

-Invisible players if you're not careful

-Server side doesn't really seem to work

-When spawning the camera seems to focus on the player again

-Maybe even more...

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