Jump to content

[Help]NFS like camera style


Xierra

Recommended Posts

Hi guys!

I have a question.

Do you know most of the NFS games?

What I mean here is that when you steer left or right (x) and not up and down, the camera will always follows it.

On GTA SA, it doesn't. I already think this is possible in MTA, so I got to figure it out how...

I dunno how to start. Can you guys tell me how? :)

Link to comment

some simple trigonometry, and getting position of vehicle, and zrotation

--clientside
local enabled=false
function getPointFromDistanceRotation(x, y, dist, angle) --credits to robhol
local a = math.rad(90 - angle)
local dx = math.cos(a) * dist
local dy = math.sin(a) * dist
return x+dx, y+dy
end
 
addCommandHandler("nfscam",function()
if enabled then
removeEventHandler("onClientRender",getRootElement(),rendercam)
else
addEventHandler("onClientRender",getRootElement(),rendercam)
end
   enabled=not enabled
end)
 
function rendercam()
local x,y,z=getElementPosition(getPedOccupiedVehicle(getLocalPlayer()))
local _,_,rotz=getElementRotation(getPedOccupiedVehicle(getLocalPlayer()))
local x2,y2=getPointFromDistanceRotation(x, y, 15, rotz+180%360)
setCameraMatrix(x,y,z,x2,y2,z+6)
end

Edited by Guest
Link to comment

try this, heres included that 3sec timer

local lastMouseTick=0
local enabled=false
 
function mousemove()
  lastMouseTick=getTickCount()
end
 
function targetcam()
if getTickCount()-3000>lastMouseTick then
setCameraTarget(getLocalPlayer())
end
end
 
function enablecam()
if enabled then
removeEventHandler("onClientMouseMove",getRootElement(),mosuemove)
removeEventHandler("onClientPreRender",getRootElement(),targetcam)
else
addEventHandler("onClientMouseMove",getRootElement(),mosuemove)
addEventHandler("onClientPreRender",getRootElement(),targetcam)
end
  enabled=not enabled
end
 
addCommandHandler("nfscam",enablecam)
bindKey("N","up","nfscam")

note:im not sure do i need use onClientMouseMove or onClientCursorMove

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