Jump to content

Problem with camera functions


Ace_Gambit

Recommended Posts

Some how I can't make the camera work like I want it. Whatever values I use for setCameraPosition, setCameraTarget and setCameraLookAt none of those give the right effect. In fact I haven't managed to move the camera to a fixed position other than somewhere at 0,0,0. No matter what values I use for setCameraPosition it always ends up at 0,0,0. Look at this code snippet for example. When simple fixed camera placement failed I tried to make a hawkview function.

meta.xml

  
<meta> 
  <info author="" description="" name="" version="1.0" type="gamemode" /> 
  
  <script src="test.lua" type="server" /> 
  <script src="test_cli.lua" type="client" /> 
  
  <map src="test.map" /> 
  
</meta> 
  

test.map

  
<map mod="deathmatch" version="1.0" time="06:00"> 
  
  <spawn posX="0" posY="0" posZ="4.0" rot="90" randx="0" randy="0" randz="0" /> 
  
  <pickup id="2" posX="0" posY="0" posZ="4.0" type="38" respawn="500" amount="6000" /> 
  
  <object name="platform" id="3" posX="0" posY="0" posZ="2.0" rotX="0.0000" rotY="0.0000" rotZ="0.0000" model="17559" /> 
  
</map> 
  

test.lua

  
function spawn() 
    if (spawnPlayer(source, 0, 0, 4.0)) then 
        fadeCamera(source, true, 5.0) 
        setCameraMode(source, "fixed") 
        createBlipAttachedTo(source, 0, 2, 0, 255, 0) 
    end 
end 
  
addEventHandler("onPlayerJoin", getRootElement(), spawn) 
  

test_cli.lua

  
function hawkview() 
    local x, y, z = getElementPosition(getLocalPlayer()) 
    setCameraPosition(getLocalPlayer(), x, y, z + 50) 
    setCameraTarget(getLocalPlayer()) 
end 
  
addCommandHandler("hawkview", hawkview) 
  

But when I test the mode and go to hawkview the camera simply goes back to chase mode :bad-words: .

Link to comment

i think you have to make all camera functions either client or server side try this for the client:

function hawkview() 
    local x, y, z = getElementPosition(getLocalPlayer()) 
    toggleCameraFixedMode (true) 
    setCameraPosition(getLocalPlayer(), x, y, z + 50) 
    setCameraTarget(getLocalPlayer()) 
end 
  
addCommandHandler("hawkview", hawkview) 

and for the serverside just leav the setcameramode function out:

function spawn() 
    if (spawnPlayer(source, 0, 0, 4.0)) then 
        fadeCamera(source, true, 5.0) 
        createBlipAttachedTo(source, 0, 2, 0, 255, 0) 
    end 
end 
  
addEventHandler("onPlayerJoin", getRootElement(), spawn) 

Edit: Hm... i think norby is right and afaik you have to use setCameraLookAt instead of setCameraTarget.

Link to comment

I already tried both your suggestions. But it seems like whenever I enable fixed camera mode I can't move the thing with setCameraPosition anymore. The camera automatically snaps to 0,0,0 every time I change to fixed mode. And it stays there no matter what values I use for setCameraPosition.

-edit-

The camera is moving now...let's try something different...

-edit-

Never mind. I hereby admit that I am a ******* idiot. I should have used setCameraPosition ( float x, float y, float z ) for the client-side instead of setCameraPosition ( player thePlayer, float x, float y, float z ) :oops: . Problem solved.

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