#Stopping force when player moves slower than they should

1 messages · Page 1 of 1 (latest)

night glen
#

I'll make it short and sweet, basically I need to make this charge function for one of my items and it works fine and dandy until you hit a wall and go flinging. I tried to make something to counter this by stopping it when they move too slow but it kinda just doesn't do that. It either stops immediately or doesn't stop at all. If anyone is willing to just try this or play with it, or inform me on better solutions let me know!

Code:

function module.chargeTarge(character,tool)
    --//Tech
    local oldJP = character.Humanoid.JumpPower
    character.Humanoid.JumpPower = 0
    
    local linearVelocity = Instance.new("LinearVelocity")
    linearVelocity.Parent = character.HumanoidRootPart
    linearVelocity.ForceLimitMode = Enum.ForceLimitMode.PerAxis
    linearVelocity.RelativeTo = Enum.ActuatorRelativeTo.Attachment0
    --linearVelocity.MaxForce = 1000000
    linearVelocity.MaxAxesForce = Vector3.new(0,0,1) * 1000000
    linearVelocity.VectorVelocity = Vector3.new(0,0,-60)
    linearVelocity.Attachment0 = character.HumanoidRootPart.RootAttachment
    
    task.spawn(combatModule.critBoostTool,tool,1.5)
    
    local chargeAnim:AnimationTrack = character.Humanoid.Animator:LoadAnimation(game.ReplicatedStorage.Animations.ShieldCharge)
    chargeAnim:Play()
    chargeAnim:AdjustSpeed(2)
    
    local sound = game.SoundService["DemoMan Charge Targe"]:Clone()
    sound.Parent = character.HumanoidRootPart
    sound.Volume = 2
    sound:Play()
    
    character.Humanoid:SetStateEnabled(Enum.HumanoidStateType.FallingDown, false)
    character.Humanoid:SetStateEnabled(Enum.HumanoidStateType.Ragdoll, false)
    character.RagdollServer.Enabled = false
    
    --// checks to see if it stopped or slowed too much
    local startTime = tick()
    local checkTick = tick()
    local lastPos = character.HumanoidRootPart.Position
    local connection 
    connection = RunService.Heartbeat:Connect(function()
        if tick() - startTime >= 1.5 then
            linearVelocity:Destroy()

            chargeAnim:Stop()
            character.Humanoid:SetStateEnabled(Enum.HumanoidStateType.FallingDown, true)
            character.Humanoid:SetStateEnabled(Enum.HumanoidStateType.Ragdoll, true)
            character.RagdollServer.Enabled = true
            character.Humanoid.JumpPower = oldJP

            connection:Disconnect()
        end
        
        local timeSpent = tick() - checkTick
        if timeSpent >= 0.3 then
            local target = linearVelocity.VectorVelocity.Magnitude
            local currentPosition = character.HumanoidRootPart.Position
            local distanceMoved = (currentPosition - lastPos).Magnitude
            local actualSpeed = distanceMoved / timeSpent
            print(actualSpeed)

            if linearVelocity.VectorVelocity.Magnitude > 20 then
                local speedRatio = actualSpeed / 60
                print(speedRatio)

                if speedRatio < 0.2 then
                    linearVelocity:Destroy()

                    chargeAnim:Stop()
                    character.Humanoid:SetStateEnabled(Enum.HumanoidStateType.FallingDown, true)
                    character.Humanoid:SetStateEnabled(Enum.HumanoidStateType.Ragdoll, true)
                    character.RagdollServer.Enabled = true
                    character.Humanoid.JumpPower = oldJP
                    task.spawn(combatModule.critBoostTool,tool,0.2)

                    connection:Disconnect()
                    return
                end
            end
        end
    end)
end
ashen hill
#

force.stop

night glen
ashen hill
#

no

night glen
obtuse cradle
night glen
obtuse cradle
#

LinearVelocity.VectorVelocity means:
the velocity the constraint wants to apply (your target speed)
AssemblyLinearVelocity means:
the physically simulated velocity of object

#

Which means when you hit a wall, AssemblyLinearVelocity will drop but LinearVelocity will still be pushing (60)

#

It naturally drops so u can just do this code

local actualSpeed = hrp.AssemblyLinearVelocity.Magnitude
if actualSpeed < 10 then
    -- You hit something or got slowed
end
night glen