Skip to content
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
59 changes: 59 additions & 0 deletions scripts/camera.lua
Original file line number Diff line number Diff line change
@@ -1,3 +1,26 @@
-------------------------
-- Snap turn variables --
-------------------------

-- To use, set to true
local snapTurnEnabled = false
local snapTurnDegrees = 15.0

-- Buffer for thumbstock x axis value
local thumbStickBuffer = 0.0

-- Has snap turn been triggered?
local snapTriggered = false

-- Time since last snap turn trigger
-- Used to debounce snap turn
local snapTimeDelta = 0.0

-------------------------
-- End snap turn --
-------------------------


local function find_required_object(name)
local obj = uevr.api:find_uobject(name)
if not obj then
Expand Down Expand Up @@ -1223,6 +1246,18 @@ local function on_level_changed(new_level)
end

uevr.sdk.callbacks.on_pre_engine_tick(function(engine, delta)

-- Snap turn debounce
if snapTriggered then
snapTimeDelta = snapTimeDelta + delta

-- 300ms timeout
if snapTimeDelta >= 0.3 then
snapTimeDelta = 0.0
snapTriggered = false
end
end

local viewport = engine.GameViewport

if viewport then
Expand Down Expand Up @@ -1747,6 +1782,21 @@ uevr.sdk.callbacks.on_post_calculate_stereo_view_offset(function(device, view_in

local hmdrot = hmd_component:K2_GetComponentRotation()
local rotdelta = hmdrot - last_rot

-- Snap turn implementation. Hijack HMD rotdelta
-- calculations to inject our own snap rotation
if snapTurnEnabled then
-- Handle right rotation
if thumbStickBuffer > 0.1 and snapTriggered == false then
rotdelta.y = rotdelta.y + snapTurnDegrees
snapTriggered = true
-- Handle left rotation
elseif thumbStickBuffer < -0.1 and snapTriggered == false then
rotdelta.y = rotdelta.y - snapTurnDegrees
snapTriggered = true
end
end

--local rotdelta = rotation - last_rot

-- Fix up the rotation delta
Expand Down Expand Up @@ -1876,6 +1926,15 @@ uevr.sdk.callbacks.on_xinput_get_state(function(retval, user_index, state)
if (state.Gamepad.wButtons & XINPUT_GAMEPAD_LEFT_THUMB) ~= 0 and (state.Gamepad.wButtons & XINPUT_GAMEPAD_RIGHT_THUMB) == 0 then
state.Gamepad.wButtons = state.Gamepad.wButtons | XINPUT_GAMEPAD_BACK
end

-- Snap turn
if snapTurnEnabled then
thumbStickBuffer = state.Gamepad.sThumbRX

-- For snap, buffer value, then clear to ignore default action
state.Gamepad.sThumbRX = 0.0
end

end)

uevr.sdk.callbacks.on_script_reset(function()
Expand Down