I have a little bit of problem with deltaTime, I thought I setted it up correctly but my character is faster at lower fps.
...
-- ## Function to clamp a Vector3
function clampVector3(vector: Vector3, min: Vector3, max: Vector3)
local clampedX = math.clamp(vector.X, min.X, max.X)
local clampedY = math.clamp(vector.Y, min.Y, max.Y)
local clampedZ = math.clamp(vector.Z, min.Z, max.Z)
return Vector3.new(clampedX, clampedY, clampedZ)
end
-- ## Movement Variables
local maxSpeed = 256
local acceleration = 20
local wishDir
local velocity
-- ## Update Movement every frame using Heartbeat
runService.Heartbeat:Connect(function(deltaTime: number)
linearVelocity.VectorVelocity = Vector3.zero
velocity = Vector3.zero
wishDir = Vector3.zero
-- Handle basic movement input
if keyStates.W then
wishDir -= Vector3.zAxis
end
if keyStates.A then
wishDir -= Vector3.xAxis
end
if keyStates.S then
wishDir += Vector3.zAxis
end
if keyStates.D then
wishDir += Vector3.xAxis
end
-- Normalize wishDir and handle division by zero
wishDir = wishDir == Vector3.zero and Vector3.zero or wishDir.Unit
if wishDir.Magnitude ~= 0 then
velocity = wishDir * acceleration
velocity = clampVector3(velocity, Vector3.new(-maxSpeed, -maxSpeed, -maxSpeed), Vector3.new(maxSpeed, maxSpeed, maxSpeed))
end
linearVelocity.VectorVelocity = velocity * character.HumanoidRootPart.AssemblyMass * deltaTime
end)
I think the problem is that LinearVelocity uses humanoid’s mass in movement, so at higher values it will move it faster, is there a way to make LinearVelocity ignore the player’s character mass?
Delta time runs on a variable frequency which is tied to your frame rate. At lower fps, your frames are more spread out and the time elapsed since the previous frame is higher, which then adds a greater multiplier effect on your velocity. An easy solution to this is to make deltaTime a constant variable like 1/60 and use that instead
but i figured out that my deltatime is working correctly, the problem was
Blockquote
I think the problem is that LinearVelocity uses humanoid’s mass in movement, so at higher values it will move it faster, is there a way to make LinearVelocity ignore the player’s character mass?
lets say at 60 fps it applies 120 force, its NOT enough to move the character
and now lets say we have 30 fps, it applies 240 force, which IS enough to move the character. thats why the problem is in the mass not deltatime