Repository navigation
Expand file tree
/
Copy pathac_chaser_camera.lua
More file actions
61 lines (50 loc) · 2.06 KB
/
Copy pathac_chaser_camera.lua
File metadata and controls
61 lines (50 loc) · 2.06 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
__source 'extensions/chaser_camera/ac_ext_chaser_camera.cpp'
require './common/internal_import'
require './inc_scene'
-- automatically generated entries go here:
__definitions()
-- extra additions:
---Reference to information about state of associated car.
---@type ac.StateCar
car = nil
---Reference to information about state of simulation.
---@type ac.StateSim
sim = nil
function __script.updateState(carIndex)
if not car or car.index ~= carIndex then
car = ac.getCar(carIndex)
if not sim then
sim = ac.getSim()
elseif type(script.onCarChanged) == 'function' then
script.onCarChanged()
end
end
end
---Gets chase camera settings.
---@return { distance: number, height: number, pitch: number }
function ac.getCameraParameters(index)
local parameters = ffi.C.lj_get_camera_params_as_vec3(index)
return { distance = parameters.x, height = parameters.y, pitch = parameters.z }
end
---@return vec2
function ac.getJoystickLook()
local parameters = ffi.C.lj_get_joystick_look()
return parameters.x ~= 0 and vec2(parameters.y, parameters.z) or nil
end
---Simple helper wrapping calls to `ac.looksLeft()`, `ac.getJoystickLook()` and such and returning a single number.
---If it’s 0.5, user wants to look to the left. If -0.5, to the right. If 1 or -1, behind (either over left or right shoulder).
---@return number
function ac.getDesiredLookDirection()
local joystickLook = ac.getJoystickLook()
local baseLookDir = (ac.looksLeft() and ac.looksRight() or ac.looksBehind()) and math.sign(lookDirection()) or
ac.looksLeft() and 0.5 or
ac.looksRight() and -0.5 or nil
return joystickLook ~= nil and (not baseLookDir or math.abs(joystickLook.x) > 0.1)
and joystickLook.x or baseLookDir or 0
end
-- script format:
---@class ScriptData
---@field update fun(dt: number) @Called each frame. Param `dt` is time since the last call of `.update()` in seconds.
---@field onCarChanged fun() @Called when selected car changes mid-run (won’t be called at the start). By the time it’s called, `car` has already been updated.
---@single-instance
script = {}