Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Added countdown options for next throw #5

Open
wants to merge 3 commits into
base: master
Choose a base branch
from
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
23 changes: 18 additions & 5 deletions bounce.lua
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ local bit = require('bit')
local bounce_type = 'dvd_bounce'
--- name of the scene item to be moved
local source_name = ''

--- if true bouncing will auto start on scene change
local start_on_scene_change = false
--- the hotkey assigned to toggle_bounce in OBS's hotkey config
Expand Down Expand Up @@ -45,11 +46,14 @@ local throw_speed_y = 50
local velocity_x = 0
--- current vertical velocity
local velocity_y = 0
--- frames to wait before throwing again
local wait_frames = 1
--- current maximum and minimal frames to wait before throwing again
local max_frames = 10
local min_frames = 60
--- frames to wait before throwing again. This variable is randomized or set using the max and min timer variables above.
local wait_frames = 0
-- physics config
local gravity = 0.98
local air_drag = 0.99
local gravity = 100 -- Gravity used to be 0.98. OBS didn't like using float so to still having the option to be accurate I instead increased the gravity by 100 times here.
local air_drag = 0.99 -- Later in the code it gets divided by 100 again. Making sure the ratio stays the same while still giving people the option to change strength with accuracy
local ground_friction = 0.95
local elasticity = 0.8

Expand Down Expand Up @@ -100,6 +104,9 @@ function script_properties()
obs.obs_properties_add_int_slider(props, 'speed', 'DVD Bounce Speed:', 1, 30, 1)
obs.obs_properties_add_int_slider(props, 'throw_speed_x', 'Max Throw Speed (X):', 1, 200, 1)
obs.obs_properties_add_int_slider(props, 'throw_speed_y', 'Max Throw Speed (Y):', 1, 100, 1)
obs.obs_properties_add_int(props, 'min_frames', 'Shortest time until next throw (seconds)', 1, 3600, 1)
obs.obs_properties_add_int(props, 'max_frames', 'Longest amount of time until next throw(seconds)', 1, 3600, 1 )
obs.obs_properties_add_int_slider(props, 'gravity', 'Strength of gravity (%) (Default is 100%)', 1, 300, 1)
obs.obs_properties_add_bool(props, 'start_on_scene_change', 'Start on scene change')
obs.obs_properties_add_button(props, 'button', 'Toggle', toggle)
return props
Expand All @@ -110,6 +117,9 @@ function script_defaults(settings)
obs.obs_data_set_default_int(settings, 'speed', speed)
obs.obs_data_set_default_int(settings, 'throw_speed_x', throw_speed_x)
obs.obs_data_set_default_int(settings, 'throw_speed_y', throw_speed_y)
obs.obs_data_set_default_int(settings, 'min_frames', min_frames)
obs.obs_data_set_default_int(settings, 'max_frames', max_frames)
obs.obs_data_set_default_int(settings, 'gravity', gravity)
end

function script_update(settings)
Expand All @@ -120,6 +130,9 @@ function script_update(settings)
speed = obs.obs_data_get_int(settings, 'speed')
throw_speed_x = obs.obs_data_get_int(settings, 'throw_speed_x')
throw_speed_y = obs.obs_data_get_int(settings, 'throw_speed_y')
min_frames= obs.obs_data_get_int(settings, 'min_frames')
max_frames = obs.obs_data_get_int(settings, 'max_frames')
gravity = obs.obs_data_get_int(settings, 'gravity') / 100
start_on_scene_change = obs.obs_data_get_bool(settings, 'start_on_scene_change')
-- don't lose original_pos when config is changed
if old_source_name ~= source_name or old_bounce_type ~= bounce_type then
Expand Down Expand Up @@ -254,7 +267,7 @@ function throw_scene_item(scene_item)

if velocity_y == 0 and velocity_x < 0.75 then
velocity_x = 0
wait_frames = 60 * 1
wait_frames = math.random(min_frames, max_frames) * 60
return
end

Expand Down