#Sliding Mechanic Help

1 messages · Page 1 of 1 (latest)

gaunt kestrel
#

So im trying to make a sliding mechanic similar to bo3 sliding. I am using AssemblyLinearVelocity to give an initial boost in the direction the player is currently facing but they keep stopping immediately after the initial boost instead of slowly losing speed. I have tried multiple things to fix this but the only thing i found that worked was BodyVelocity which is deprecated :/ I am also trying to get the player to follow slopes when using the slide ability instead of flying off them, which I thought I could do with raycasting but when I try to teleport the player to the raycast hit position + hip height + 1/2 root part size the player model stops aligning with the camera and just starts rotating and moving seemingly randomly every time i slide.
tldr

  1. how to make the player slowly lose speed instead of stopping immediately after setting AssemblyLinearVelocity
  2. how to properly teleport player down to where the raycast hits so their model doesnt fly off into the stratosphere

the slide function:

    if value and not exhausted and not sliding then
        sliding = true
        _sprint(false)
        slide_anim:Play(0.25, 1.0, 1.0)
        stamina = math.max(0, stamina - slide_cost)
        if stamina == 0 then
            _setExhausted(true)
        end
        _updateStaminaUI()
        slide_velocity = Vector3.new(root_part.CFrame.LookVector.X * 100, 0, root_part.CFrame.LookVector.Z * 100)
        humanoid.WalkSpeed = 0.0
        root_part.AssemblyLinearVelocity = slide_velocity
        slide_time = 2
    else
        sliding = false
        slide_anim:Stop(0.25)
        humanoid.WalkSpeed = walk_speed
    end
end```
#

the slide section of the heartbeat function:

        local raycastParams = RaycastParams.new()
        raycastParams.FilterDescendantsInstances = {script.Parent}
        raycastParams.FilterType = Enum.RaycastFilterType.Exclude
        local raycastResult = workspace:Raycast(root_part.Position, Vector3.new(0,-5,0), raycastParams)
        if raycastResult then
            --print(raycastResult.Position.Y, root_part.Position.Y, hip_height + root_part.Size.Y/2)
            root_part.Position = Vector3.new(root_part.Position.X, raycastResult.Position.Y + hip_height + root_part.Size.Y/2, root_part.Position.Z)
        end
        slide_time = math.max(0, slide_time - 5 * deltaTime)
        if slide_time == 0 then
            _slide(false)
        end
    else```