Jump to content

First Person Script Help


Recommended Posts

function firstPerson(player) 
    x,y,z = getElementPosition(player) 
    rx,ry,rz = getElementPosition(player) 
    setCameraMatrix(player1,x,y,z + 1,rx + 1,ry,rz) 
    resetTime = setTimer (firstPerson, 100, 0, player) 
end 
addCommandHandler("fp", firstPerson) 

Made this script to make a first person camera but i cant make the camera follow the player as the console has a seizure and gives me lots of errors. How to fix? Also after this ill have the problem of needing to move the players vision with the mouse. How can i make that work? And how to make it so that the camera is facing ahead of the player.

Link to comment
You should make a client side script which updates camera onClientPreRender.

Try this:

function firstPerson() 
    x,y,z = getElementPosition(localPlayer) 
    rx,ry,rz = getElementPosition(localPlayer) 
    setCameraMatrix(x,y,z + 1,rx + 1,ry,rz) 
end 
addCommandHandler("fp", function() 
    addEventHandler("onClientPreRender",root,firstPerson) 
end) 

BTW, I suggest getting the player's bone position:

getPedBonePosition 

Link to comment
setPedLookAt

Instead, create a object, move it on prerender, moving the mouse moves the object. and have the lookat (ped and camera) point towards the object.

i have got it to work now but its sketchy as! Instead of making an object ive just been using the cursors position. I think making an object would work much better, how do i do this though? (not the making the object, the making it move with the mouse) heres what ive got.

function firstPerson() 
    x,y,z = getPedBonePosition(localPlayer, 7) 
    showCursor(true, false) 
    s1,s2,cx,cy,cz = getCursorPosition(localPlayer) 
    setCameraMatrix(x,y,z,cx,cy,cz) 
    setPedLookAt(localPlayer,cx,cy,cz,-1) 
end 
addCommandHandler("fp", function() 
    addEventHandler("onClientPreRender",root,firstPerson) 
end) 

Link to comment
function firstPerson() 
    rx,ry,rz = getElementRotation(localPlayer) 
    screenX, screenY = guiGetScreenSize () 
    x,y,z = getPedBonePosition(localPlayer, 7) 
    showCursor(true, false) 
    s1,s2,cx,cy,cz = getCursorPosition(localPlayer) 
    setCameraMatrix(x,y,z,cx,cy,cz,ry,180) 
    setPedLookAt(localPlayer,cx,cy,cz,-1) 
    if s1>0.55 then 
        setCursorPosition(screenX/2 + 20, screenY/2) 
    end 
    if s1<0.45 then 
        setCursorPosition(screenX/2 - 20, screenY/2) 
    end 
    if s2>0.55 then 
        setCursorPosition(screenX/2, screenY/2 + 20) 
    end 
    if s2<0.45 then 
        setCursorPosition(screenX/2, screenY/2 - 20) 
    end 
end 
addCommandHandler("fp", function() 
    addEventHandler("onClientPreRender",root,firstPerson) 
end) 

this works but i need to make a function so i can go back to normal camera by typing /tp

i also would like to know how to make the cross hairs appear when i right click

Link to comment
addCommandHandler("tp", function() 
    removeEventHandler("onClientPreRender",root,firstPerson) 
    setCameraTarget(localPlayer,localPlayer) 
end) 
  

You can't use gta crosshair while using setCameraMatrix , you will need to make your own

Link to comment
addCommandHandler("tp", function() 
    removeEventHandler("onClientPreRender",root,firstPerson) 
    setCameraTarget(localPlayer,localPlayer) 
end) 
  

You can't use gta crosshair while using setCameraMatrix , you will need to make your own

thanks mate,works fine now. I'll figure out something for cross hairs. If anyone can help me there though would be appreciated

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