Hello, first post on the dev forum, I’m making a parkour game with some similar mechanics to Flood Escape 2. One of those mechanics being sliding. Here is the module script right now:
function abilitytable.slide(Character, Track: AnimationTrack) -- Character model and animation to be played, passed along from requiring local script
game.ReplicatedStorage.RemoteEvents.Slide.Slide:FireServer() -- This is just for updating the stamina bar and communication across the client
local hrp = Character:WaitForChild("HumanoidRootPart")
local lv = Instance.new("LinearVelocity", hrp)
local Attach0 = Instance.new("Attachment", hrp)
lv.RelativeTo = Enum.ActuatorRelativeTo.Attachment0
lv.Attachment0 = Attach0
lv.ForceLimitMode = Enum.ForceLimitMode.PerAxis
lv.MaxAxesForce = Vector3.new(100000, 0, 100000)
lv.VectorVelocity = Vector3.new(0, 0, -20)
script.Slide2.PlaybackSpeed = math.random(95, 105) / 100 -- Playback speed of sound effect is randomized
script.Slide2:Play()
Track:Play(0.1, nil, 2)
repeat task.wait() until (UIS:IsKeyDown(Enum.KeyCode.E) == false) -- Wait until the E key is released to stop sliding
or (Character:WaitForChild("Humanoid").FloorMaterial == Enum.Material.Air) -- Or if the character is in the air then stop sliding
or (Character:WaitForChild("Humanoid").FloorMaterial == nil)
lv:Destroy()
Track:Stop()
Attach0:Destroy()
end
I’m not that good at scripting so there is definitely some room for improvement here and dealing with physics, CFrames, etc. just isn’t my strong suit.
Anyway, with how the mechanic is currently implemented, the player can still turn while sliding. From the moment they hold E, the direction of the linear velocity must lock so that the player cannot turn. That isn’t seemingly possible with it being relative to an attachment.
For comparison, here is the expected behavior [Top] and the current behavior [Bottom]. Observe how with the expected behavior, turning with shiftlock while sliding does not change the direction the player slides in.
(The fumbling sound at the end of the clip is from in-game)
I have tried using the look vector of the humanoidrootpart and changing the rotation of the attachment very rapidly and offsets, all that stuff, but it does not seem possible without making the direction of the linear velocity in global space. Issue is, the linear velocity just stops working altogether when relative to the world. So hopefully someone can help me out. Cheers.