#Friction problems

1 messages · Page 1 of 1 (latest)

little pecan
#
        [Enum.KeyCode.W] = Vector3.new(0, 0, -1),
        [Enum.KeyCode.S] = Vector3.new(0, 0, 1),
        [Enum.KeyCode.D] = Vector3.new(1, 0, 0),
        [Enum.KeyCode.A] = Vector3.new(-1, 0, 0)
    }
    

    for key, force in pairs(forceTable) do
        if keys[key] then
            local horizVel = Vector3.new(vel.X, 0, vel.Z)
            if horizVel.Magnitude < TOP_SPEED then
                root:ApplyImpulse(force * root.AssemblyMass * ACCEL * dt)
            end
        end
    end

    local horizVel = Vector3.new(vel.X, 0, vel.Z)
    if horizVel.Magnitude > 0.01 then
        root:ApplyImpulse(20*-horizVel.Unit * root.AssemblyMass * FRICTION * dt)
    end

    local avatarCFrame = CFrame.new(ballPos + Vector3.new(0, root.Size.Y / 2, 0))
        * CFrame.Angles(0, facingAngle, 0)

I'm working on a game and i'm working with push forces in different directions. I need friction to work, but the problem is that the friction only applies in the exact opposite direction of current movement making it so holding another direction slows down friction in every other direction. Is there a different approach i could take to this problem to solve this issue?

trail apex
#

try to use this

#

`local horizVel = Vector3.new(vel.X, 0, vel.Z)

if horizVel.Magnitude > 0 then
local frictionImpulse = Vector3.new(
-vel.X * FRICTION,
0,
-vel.Z * FRICTION
) * root.AssemblyMass * dt

root:ApplyImpulse(frictionImpulse)

end`

#

local horizVel = Vector3.new(vel.X, 0, vel.Z)

if horizVel.Magnitude > 0 then
local frictionImpulse = Vector3.new(
-vel.X * FRICTION,
0,
-vel.Z * FRICTION
) * root.AssemblyMass * dt

root:ApplyImpulse(frictionImpulse)

end

#

also the next bit s optional if the friction is too high it may lower velocity.

local function damp(value, amount)
if math.abs(value) < amount then
return 0
end
return value - math.sign(value) * amount
end

local newX = damp(vel.X, FRICTION * dt)
local newZ = damp(vel.Z, FRICTION * dt)

local frictionImpulse = Vector3.new(
newX - vel.X,
0,
newZ - vel.Z
) * root.AssemblyMass

root:ApplyImpulse(frictionImpulse)

little pecan
#

alright, that works