Character falls over after custom knockback system fires

I’m working on a recreation of an old game I used to play which is now discontinued, and my concurrent “knockback” system does not allow the player to recover correctly, and makes the player fall over at the end. The falling over only happens in-game, not in studio.

The following code is what fires after you land

(the beginning of said lines listed are me trying to figure out how to fix the sudden slipping the line where I clear out all of “Velocities” is where the actual part where I slide backwards.)

	RootPart.AssemblyLinearVelocity = Vector3.new(0,0,0);
		RootPart.CFrame = CFrame.lookAt(RootPart.Position + Vector3.new(0,2.5,0), Vector3.new(Point.X, RootPart.Position.Y + 2.5, Point.Z))
		local bodygyro = Instance.new("BodyGyro")
		bodygyro.CFrame = RootPart.CFrame;
		bodygyro.MaxTorque = Vector3.new(math.huge,math.huge,math.huge)
		bodygyro.D = 0
		bodygyro.P = 1500
		bodygyro.Parent = RootPart;
		local bodypos = Instance.new("BodyPosition")
		bodypos.MaxForce = Vector3.new(math.huge,math.huge,math.huge)
		bodypos.P = 1500
		bodypos.D = 0
		bodypos.Position = RootPart.Position;
		bodypos.Parent = RootPart
		Debris:AddItem(bodygyro,.4)
		Debris:AddItem(bodypos,.1)
		RootPart.Anchored = false;
		if Humanoid then
			Humanoid:ChangeState(Enum.HumanoidStateType.Landed)
		end

		for i,v in pairs(Velocities) do
			v:Destroy()
		end
		Part_that_Emulates:Destroy()
		InState:Destroy()
		InAirAnimation:Stop()
		RebalanceAnimation:Play()

		local beginningtick = -56.50
		local bodyvel = Instance.new("BodyVelocity")
		bodyvel.MaxForce = Vector3.new(math.huge,0,math.huge)
		bodyvel.P = 12500
		bodyvel.Velocity = RootPart.CFrame.LookVector * beginningtick
		bodyvel.Parent = Character:FindFirstChild("Torso")
		game.Debris:AddItem(bodyvel,1.25)

		repeat task.wait()
			local Rayca = workspace:Raycast(RootPart.Position + RootPart.Velocity / 5, RootPart.CFrame.LookVector * -8,param)
			if Rayca then
				bodyvel.Velocity = Direction * -Rayca.Distance
			else
				bodyvel.Velocity = Direction * beginningtick
			end
		until bodyvel.Parent == nil or bodyvel == nil or Humanoid == nil or Humanoid.Health <= 0 or Character == nil or Character.Parent == nil
		if bodyvel ~= nil then
			bodyvel:Destroy()
		end
		Humanoid.AutoRotate = true;

I’m aware that the code is a mess, but I’ll get to that part later.

So I see you set the HumanoidState to be Landed, what if you had a loop running in parallel that consistently set the humanoid to the Landed state after they have been flung? Also, I don’t know if this would change anything, but what if you manually set PlatformStand to true just before the knockback is applied?

Thank you, I added the humanoidstate change into a loop and made it toggle PlatformStand at the start and the end of the knockback, which fixed it.

1 Like

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