Skip to content

Commit

Permalink
(0.635.0.6350588)
Browse files Browse the repository at this point in the history
  • Loading branch information
EgoMoose authored and github-actions[bot] committed Jul 30, 2024
1 parent fa91c3c commit b4cc6ac
Show file tree
Hide file tree
Showing 3 changed files with 33 additions and 5 deletions.
32 changes: 30 additions & 2 deletions src/RbxCharacterSounds/init.client.lua
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,8 @@ local function loadFlag(flag: string)
return success and result
end

local FFlagUserSoundsUseRelativeVelocity = loadFlag('UserSoundsUseRelativeVelocity2')

local SOUND_DATA : { [string]: {[string]: any}} = {
Climbing = {
SoundId = "rbxasset://sounds/action_footsteps_plastic.mp3",
Expand Down Expand Up @@ -54,6 +56,23 @@ local function map(x: number, inMin: number, inMax: number, outMin: number, outM
return (x - inMin)*(outMax - outMin)/(inMax - inMin) + outMin
end

local function getRelativeVelocity(cm, velocity)
if not cm then
return velocity
end
local activeSensor = cm.ActiveController and
(
(cm.ActiveController:IsA("GroundController") and cm.GroundSensor) or
(cm.ActiveController:IsA("ClimbController") and cm.ClimbSensor)
)
if activeSensor and activeSensor.SensedPart then
-- Calculate the platform relative velocity by subtracting the velocity of the surface we're attached to or standing on.
local platformVelocity = activeSensor.SensedPart:GetVelocityAtPosition(cm.RootPart.Position)
return velocity - platformVelocity
end
return velocity
end

local function playSound(sound: Sound)
sound.TimePosition = 0
sound.Playing = true
Expand All @@ -72,6 +91,12 @@ local function initializeSoundSystem(instances)
local humanoid = instances.humanoid
local rootPart = instances.rootPart

local cm = nil
if FFlagUserSoundsUseRelativeVelocity then
local character = humanoid.Parent
cm = character:FindFirstChild('ControllerManager')
end

local sounds: {[string]: Sound} = {}

-- initialize sounds
Expand Down Expand Up @@ -154,7 +179,9 @@ local function initializeSoundSystem(instances)

[Enum.HumanoidStateType.Climbing] = function()
local sound = sounds.Climbing
if math.abs(rootPart.AssemblyLinearVelocity.Y) > 0.1 then
local partVelocity = rootPart.AssemblyLinearVelocity
local velocity = if FFlagUserSoundsUseRelativeVelocity then getRelativeVelocity(cm, partVelocity) else partVelocity
if math.abs(velocity.Y) > 0.1 then
sound.Playing = true
stopPlayingLoopedSounds(sound)
else
Expand All @@ -176,7 +203,8 @@ local function initializeSoundSystem(instances)
-- updaters for looped sounds
local loopedSoundUpdaters: {[Sound]: (number, Sound, Vector3) -> ()} = {
[sounds.Climbing] = function(dt: number, sound: Sound, vel: Vector3)
sound.Playing = vel.Magnitude > 0.1
local velocity = if FFlagUserSoundsUseRelativeVelocity then getRelativeVelocity(cm, vel) else vel
sound.Playing = velocity.Magnitude > 0.1
end,

[sounds.FreeFalling] = function(dt: number, sound: Sound, vel: Vector3): ()
Expand Down
4 changes: 2 additions & 2 deletions src/VersionInfo.json
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
{
"version": "0.573.0.5730507",
"guid": "version-da56b3062bbf4871"
"version": "0.635.0.6350588",
"guid": "version-258fa44b42074cfc"
}
2 changes: 1 addition & 1 deletion wally.toml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
[package]
name = "upliftgames/rbxcharactersounds"
version = "573.0.5730507"
version = "635.0.6350588"
registry = "https://github.com/UpliftGames/wally-index"
realm = "shared"

Expand Down

0 comments on commit b4cc6ac

Please sign in to comment.