Jump to content

Need help


xxMANxx

Recommended Posts

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

  • Thanks 1
Link to comment
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

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