Physics problems

So I’ve been working on a sorta double jump system with some other details, so it uses physics, only problem is this happens:

So uh anyone know a way I can fix this?
if there isnt exactly a way to stop the physics from doing this Ill just destroy the linear velocity sooner.

Not sure if this is exactly scriping but whatever

You need to provide the code. This could be caused by many things.

1 Like
module.abilites['DoubleJump'] = function(player:Player)
	
	local char = player.Character
	
	-- instances
	local root = char.PrimaryPart
	local rootAttach = root:FindFirstChild('RootAttachment')
	local hum = char:FindFirstChildOfClass('Humanoid')
	
	-- set values of hum
	hum.WalkSpeed = 0
	
	-- double jump
	local velocity:LinearVelocity
	
	if root:FindFirstChildOfClass('LinearVelocity') then
		root:FindFirstChildOfClass('LinearVelocity'):Destroy()
	end
	velocity = Instance.new('LinearVelocity')
	velocity.Attachment0 = rootAttach
	velocity.RelativeTo = Enum.ActuatorRelativeTo.Attachment0
	
	velocity.MaxForce = math.huge
	velocity.VectorVelocity = Vector3.new(0,50,-30)
	velocity.Parent = root
	wait(0.5)
	repeat
		velocity.VectorVelocity -= Vector3.new(0,10,0)
		task.wait(0.1)
	until velocity.VectorVelocity.Y == -65
	
	repeat
		task.wait()
	until hum.FloorMaterial.Name ~= 'Air' 
	velocity:Destroy()
	return
end

Basically this function makes them go up and then down, Im pretty sure the reason it happens is caused by the linear velocity pushing the player into the ground.


(LinearVelocity | Documentation - Roblox Creator Hub)
The documentation says it applies forces to maintain a constant linear velocity. It likely causes issues because it can’t maintain the velocity if the player is grounded. Like this image recommends, you should probably set AssemblyLinearVelocity and you also won’t have to deal with the LinearVelocity objects.

Ohh thanks! This is the first time I’ve used it so yeah lol.
Ill try it out in the morning (Its late for me)

1 Like

Wait so what exactly does AssemblyLinearVelocity do? I looks like it works like linearVelocity but whats the difference?


Ok I tried it, this happened, which I dont think is normal sooooo.
Heres my modified code

module.abilites['DoubleJump'] = function(player:Player)
	
	local char = player.Character
	
	-- instances
	local root = char.PrimaryPart
	local rootAttach = root:FindFirstChild('RootAttachment')
	local hum = char:FindFirstChildOfClass('Humanoid')
	
	-- set values of hum
	hum.WalkSpeed = 0
	
	-- double jump
	local velocity:LinearVelocity
	
	if root:FindFirstChildOfClass('LinearVelocity') then
		root:FindFirstChildOfClass('LinearVelocity'):Destroy()
	end

	root.AssemblyLinearVelocity = Vector3.new(0,50,-30)

	wait(0.5)
	repeat
		root.AssemblyLinearVelocity -= Vector3.new(0,10,0)
		task.wait(0.1)
	until root.AssemblyLinearVelocity.Y == -65
	
	repeat
		task.wait()
	until hum.FloorMaterial.Name ~= 'Air' 
	
	--velocity:Destroy()
	return
end

You should not set the AssemblyLinearVelocity directly. You should add onto it.

The issues with your code that I noticed:

  1. You’re manually decreasing the Y velocity of the HRP for gravity. You don’t need to adjust this because roblox automatically handles it. The assembly linear velocity IS the current velocity of that object, so you are applying additional gravity (roblox automatically applies gravity and updates assembly linear velocity). This causes your character to be pushed into the ground even when you’re not jumping.
  2. In the gravity you added in issue #1, you’re waiting until the velocity’s Y component is exactly equal to -65, which is nearly impossible to fulfill with time steps of 0.1, even with the velocity being automatically updated. More than that, it would probably never reach that velocity anyways because the player will probably hit the ground under them faster than they can get to -65 Y velocity. This is the second part that causes your character to be pushed into the ground after you stop jumping.
  3. In the way you change the assembly linear velocity initially in the function, you are setting -30 for Z velocity. This probably isn’t what you want because AssemblyLinearVelocity is in global space, not object space, so it moves your character on the global Z axis, which probably isn’t intentional. You can do CFrame * Vector3 to get the Vector3 translated from object to global space.
    (CFrame | Documentation - Roblox Creator Hub)

In async functions like this, you should make sure that you don’t have unwanted overlapping behavior. If you jump and, before the wait(0.5) finishes, you jump again, you will have multiple changes to your velocity which can lead to choppy and undesirable behavior.

I apply the linear velocity to make them go down cause it makes it look so much smoother.

Omg I did not realize this at all let me go fix this.
Just did it, the problem is fixed now so thank you so much lol!

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