aneco Posted May 29, 2011 Share Posted May 29, 2011 (edited) hi i found a script which player press f2 and have first person camera but i have a problem when player steers a car the cam wont steer and player have to steer camera via mouse i couldnt make a fix for this and i need some help please help me i need this code soo much. Here is the code which i found local x, y, z, x1, y1, z1 local fpcam = false bindKey( "F2", "down", function() if fpcam then setCameraTarget(getLocalPlayer(), getLocalPlayer()) end fpcam = not fpcam end ) addEventHandler("onClientPreRender", root, function() if fpcam then x, y, z = getPedBonePosition(getLocalPlayer(), 6) setCameraMatrix(x, y, z, x + x1, y + y1, z + z1) dxDrawImage(screenWidth/2-10, screenHeight/2-10, 20, 20, "images/aimer.png") local tarX, tarY, tarZ = getWorldFromScreenPosition(screenWidth/2, screenHeight/2, 30) setPedAimTarget(getLocalPlayer(), tarX, tarY, tarZ) end end ) addEventHandler("onClientCursorMove", root, function( _, _, _, _, wx, wy, wz ) local cx, cy, cz = getCameraMatrix() x1 = ( wx - cx ) / 300 y1 = ( wy - cy ) / 300 z1 = ( wz - cz ) / 300 end ) Edited May 29, 2011 by Guest Link to comment
qaisjp Posted May 29, 2011 Share Posted May 29, 2011 That is made by bmat, don't say you made it! Link to comment
aneco Posted May 29, 2011 Author Share Posted May 29, 2011 That is made by bmat, don't say you made it! okey but do you help me about fix? Link to comment
qaisjp Posted May 30, 2011 Share Posted May 30, 2011 Hm. So you want to move the mouse to drive, right? I don't know, I have an idea though. Link to comment
karlis Posted May 30, 2011 Share Posted May 30, 2011 (edited) get the car Z rotation, then calculate wx, and wy with function function getPointFromDistanceRotation(x,y,dist,angle) local a=math.rad(90-angle) local dx=math.cos(a)*dist local dy=math.sin(a)*dist return x+dx,y+dy end by using this if getControlState"left" or getControlState"right" then local _,_,Zrot=getElementRotation(getPedOccupiedVehicle(getLocalPlayer())) wx,wy=getPointFromDistanceRotation(cx,cy,((cx-wx)^2+(cy-wy)^2)^0.5,Zrot) end Edited May 30, 2011 by Guest Link to comment
qaisjp Posted May 30, 2011 Share Posted May 30, 2011 He wants to use the mouse to steer the car, like how flying using mouse. Link to comment
karlis Posted May 30, 2011 Share Posted May 30, 2011 i suggest to re-read the 1st post, that works, he just hate that he have to turn cam manually on turns. btw i still failed with advice aswell, editing it now. Link to comment
qaisjp Posted May 30, 2011 Share Posted May 30, 2011 This is confusing, I hate it when people edit it to make things different -.- Then whatever people said become fake. You should make a new post with the code, not edit it. Link to comment
aneco Posted May 30, 2011 Author Share Posted May 30, 2011 get the car Z rotation, then calculate wx, and wy with function function getPointFromDistanceRotation(x,y,dist,angle) local a=math.rad(90-angle) local dx=math.cos(a)*dist local dy=math.sin(a)*dist return x+dx,y+dy end by using this if getControlState"left" or getControlState"right" then local _,_,Zrot=getElementRotation(getPedOccupiedVehicle(getLocalPlayer())) wx,wy=getPointFromDistanceRotation(cx,cy,((cx-wx)^2+(cy-wy)^2)^0.5,Zrot) end where i should put this code to script.i make like this. local x, y, z, x1, y1, z1 local fpcam = false bindKey( "F2", "down", function() if fpcam then setCameraTarget(getLocalPlayer(), getLocalPlayer()) end fpcam = not fpcam end ) addEventHandler("onClientPreRender", root, function() if fpcam then x, y, z = getPedBonePosition(getLocalPlayer(), 6) setCameraMatrix(x, y, z, x + x1, y + y1, z + z1) dxDrawImage(screenWidth/2-10, screenHeight/2-10, 20, 20, "images/aimer.png") local tarX, tarY, tarZ = getWorldFromScreenPosition(screenWidth/2, screenHeight/2, 30) setPedAimTarget(getLocalPlayer(), tarX, tarY, tarZ) function getPointFromDistanceRotation(x,y,dist,angle) local a=math.rad(90-angle) local dx=math.cos(a)*dist local dy=math.sin(a)*dist return x+dx,y+dy if getControlState"left" or getControlState"right" then local _,_,Zrot=getElementRotation(getPedOccupiedVehicle(getLocalPlayer())) wx,wy=getPointFromDistanceRotation(cx,cy,((cx-wx)^2+(cy-wy)^2)^0.5,Zrot) end end end ) addEventHandler("onClientCursorMove", root, function( _, _, _, _, wx, wy, wz ) local cx, cy, cz = getCameraMatrix() x1 = ( wx - cx ) / 300 y1 = ( wy - cy ) / 300 z1 = ( wz - cz ) / 300 end ) Link to comment
karlis Posted May 30, 2011 Share Posted May 30, 2011 local x, y, z, x1, y1, z1 local fpcam = false bindKey( "F2", "down", function() if fpcam then setCameraTarget(getLocalPlayer(), getLocalPlayer()) end fpcam = not fpcam end ) addEventHandler("onClientPreRender", root, function() if fpcam then x, y, z = getPedBonePosition(getLocalPlayer(), 6) if isPedInVehicle(getLocalPlayer()) and (getControlState"left" or getControlState"right") then local _,_,Zrot=getElementRotation(getPedOccupiedVehicle(getLocalPlayer())) x1,y1=getPointFromDistanceRotation(x,y,(x1^2+x1^2)^0.5,Zrot) end setCameraMatrix(x, y, z, x + x1, y + y1, z + z1) dxDrawImage(screenWidth/2-10, screenHeight/2-10, 20, 20, "images/aimer.png") local tarX, tarY, tarZ = getWorldFromScreenPosition(screenWidth/2, screenHeight/2, 30) setPedAimTarget(getLocalPlayer(), tarX, tarY, tarZ) end) function getPointFromDistanceRotation(x,y,dist,angle) local a=math.rad(90-angle) local dx=math.cos(a)*dist local dy=math.sin(a)*dist return x+dx,y+dy end addEventHandler("onClientCursorMove", root, function( _, _, _, _, wx, wy, wz ) local cx, cy, cz = getCameraMatrix() x1 = ( wx - cx ) / 300 y1 = ( wy - cy ) / 300 z1 = ( wz - cz ) / 300 end ) Link to comment
aneco Posted May 30, 2011 Author Share Posted May 30, 2011 it doesnt work when i f2 it dopesnt do anythink i tried to run script clientside and serverside too but didnt worked Link to comment
Recommended Posts
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 accountSign in
Already have an account? Sign in here.
Sign In Now