xxMANxx Posted August 11, 2019 Share Posted August 11, 2019 I am doing first-person view and want to limit the camera so that it does not rotate 360 degrees. if cameraRotation > playerRotation + 90 then cameraRotation = playerRotation + 90 elseif cameraRotation < playerRotation - 90 then cameraRotation = playerRotation - 90 end Everything works until playerRotation becomes 350, and the cameraRotation >360 and becomes 0, then the condition works, but it should not work. Link to comment
Scripting Moderators thisdp Posted August 12, 2019 Scripting Moderators Share Posted August 12, 2019 addEventHandler("onClientRender",root,function() local _,_,playerRotation = getElementRotation(localPlayer) local cameraRotation = 360 - getPedCameraRotation(localPlayer) local cameraRad = math.rad(cameraRotation) local playerRad = math.rad(playerRotation) local includedAngle = math.cos(cameraRad-playerRad) local angleSymbol = math.sin(cameraRad-playerRad) if includedAngle < 0 then cameraRotation = playerRotation + 90*(angleSymbol > 0 and 1 or -1) setPedCameraRotation(localPlayer,cameraRotation) end end) Better to use cos/sin to solve this problem 1 Link to comment
xxMANxx Posted August 12, 2019 Author Share Posted August 12, 2019 56 minutes ago, thisdp said: addEventHandler("onClientRender",root,function() local _,_,playerRotation = getElementRotation(localPlayer) local cameraRotation = 360 - getPedCameraRotation(localPlayer) local cameraRad = math.rad(cameraRotation) local playerRad = math.rad(playerRotation) local includedAngle = math.cos(cameraRad-playerRad) local angleSymbol = math.sin(cameraRad-playerRad) if includedAngle < 0 then cameraRotation = playerRotation + 90*(angleSymbol > 0 and 1 or -1) setPedCameraRotation(localPlayer,cameraRotation) end end) Better to use cos/sin to solve this problem it works thank you so much 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