Jump to content

Camera behavior question


JoeBlack

Recommended Posts

Hi all, ty for ur job on mta! My question is:

When u drive car, default camera follow it behind ur car, but when u turn and don't use any camera abilities (i mean like u turn right and use mouse to put camera back to center before gta do it), camera restores to center of car with little timeout, actually i think it happens after wheels become straight again and 2-3 secs timeout. Okay, u all now how it works, i want to make something like this:

it okay if u can use mouse to rotate camera when u drive, but imagine if u cant use mouse for it, also move camera with buttons not actually thing that i want.
I already read about setCameraMatrix, setCameraTarget, setElementMatrix, setFieldOfView etc... But i rlly cant figure out with this vectors and other mathematical stuff(((

The reason i need this cause i try to play gta with wheel and all fine except when i turn i cant put camera back to center because i cant use mouse this moment, and buttons are quite fast so its rlly very hard to drive in turns and use buttons to move camera to center. 
 

So i want achieve that camera angle when i turn cannot be greater then some config variable like this:

mta-screen-2019-09-12-17-42-39.png

instead of this:

mta-screen-2019-09-12-17-35-50.png

tnx for ur help )))

Link to comment

Okay, i write this code and it sets camera always behind car when i press A/D keys(when i turn).

 

local camState = false
local cameraHookEnabled = false
local origFieldOfView = 0
local cameraResetTimer

function vehicleCameraHookUpdate()
	if not isPedInVehicle(localPlayer) then return end

	local vehicle = getPedOccupiedVehicle (localPlayer)

	if getVehicleController(vehicle) ~= localPlayer then return end

	local vehLeftState = getPedAnalogControlState( localPlayer, "vehicle_left" )
	local vehRightState = getPedAnalogControlState( localPlayer, "vehicle_right" )

	if (vehLeftState > 0.3 or vehRightState > 0.3) then 
		camState = true 
	else camState = false end

	if camState then
    	-- I found this code somewhere in forum, it does something like i need but not smooth at all and camera always goes up after turning a while.
    	-- I have no idea what this code actually do.
		local Sx,Sy,Sz = getElementPosition (vehicle) 
		local _,_,pR = getElementRotation (localPlayer) 
		pR =  ((pR+90) * 3.141592653 * 2)/360; --edit "90" to change the rotation. 
		local lookAtX, lookAtY, lookAtZ = Sx + math.cos(pR), Sy + math.sin(pR), Sz
		setCameraTarget( lookAtX, lookAtY, lookAtZ )
		-- This makes camera always behind car and best solution i found wich at least works, but is it good solution at all on every render update?
	 	-- setCameraTarget(localPlayer)
		-- setCameraMatrix(0, 0, 0)
		-- setCameraTarget(localPlayer)
	end

end

addEventHandler("onClientPreRender", root, vehicleCameraHookUpdate)

Now my question is how to get correct X,Y,Z for setCameraTarget so when i turn maximum look offset should be like i posted in screenshot 1 in topic and not only behind car like my code do. 

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