From b4cc6ac1d4e9d358dc7966ca1dcac46f39a614fc Mon Sep 17 00:00:00 2001 From: EgoMoose Date: Tue, 30 Jul 2024 14:53:51 +0000 Subject: [PATCH] (0.635.0.6350588) --- src/RbxCharacterSounds/init.client.lua | 32 ++++++++++++++++++++++++-- src/VersionInfo.json | 4 ++-- wally.toml | 2 +- 3 files changed, 33 insertions(+), 5 deletions(-) diff --git a/src/RbxCharacterSounds/init.client.lua b/src/RbxCharacterSounds/init.client.lua index 71aa2fb..bb4429d 100644 --- a/src/RbxCharacterSounds/init.client.lua +++ b/src/RbxCharacterSounds/init.client.lua @@ -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", @@ -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 @@ -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 @@ -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 @@ -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): () diff --git a/src/VersionInfo.json b/src/VersionInfo.json index ec17021..8f1fe18 100644 --- a/src/VersionInfo.json +++ b/src/VersionInfo.json @@ -1,4 +1,4 @@ { - "version": "0.573.0.5730507", - "guid": "version-da56b3062bbf4871" + "version": "0.635.0.6350588", + "guid": "version-258fa44b42074cfc" } \ No newline at end of file diff --git a/wally.toml b/wally.toml index e15a4da..2aab21f 100644 --- a/wally.toml +++ b/wally.toml @@ -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"