LinearVelocity mass ignore

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)
2 Likes

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?

Your issue is deltaTime*

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

aside from what @DataSigh said

why do you update the movement every frame? wouldn’t it just be easier to do it via user input service or something?

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?

Why would your fps be the thing affecting the mass, but not affecting delta time which is directly linked to your frame rate?

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

but if you just use normal linear velocity without delta time, the force will always be the same

lower fps = faster dash, this is caused by delta time D:

you could make the character massless during the force but is that optimal? probably not

This topic was automatically closed 14 days after the last reply. New replies are no longer allowed.