How to cancel momentum for grab attack

I am trying to make a grab attack, however whenever the two players collide and bump into eachother, instead of the player teleporting in front of the other, they are farther away because of the momentum.
Example:
What happens if they don’t bump (it should always be like this): https://i.gyazo.com/da1cb5ac23bfd8dece34669297b0e7e0.mp4
What happens if they bump:
https://i.gyazo.com/14c6a15dea67ea0ac2932cf3e2cdc46f.mp4

If possible, i don’t want to change the players colliding with eachother normally, down below is the code I use, any help is appreciated
(Ignore the messy attachments, im new to using particles)

Remote.OnServerEvent:Connect(function(player)
	local Char = player.Character or player.CharacterAdded:Wait()
	local Hum = Char:WaitForChild("Humanoid")
	local HumRP = Char:WaitForChild("HumanoidRootPart")
	local dashSpeed = 80 --Speed of dash
	local hit = false
	
	print("Beginning dash attack")
	
	task.wait(1)
	
	local attachment = Instance.new("Attachment")
	attachment.Name = "DashAttachment0"
	attachment.Parent = HumRP

	local linearVelocity = Instance.new("LinearVelocity")
	linearVelocity.Attachment0 = attachment
	linearVelocity.VelocityConstraintMode = Enum.VelocityConstraintMode.Plane
	linearVelocity.PrimaryTangentAxis = Vector3.new(1, 0, 0)
	linearVelocity.SecondaryTangentAxis = Vector3.new(0, 0, 1)
	linearVelocity.MaxForce = math.huge
	linearVelocity.Enabled = false
	linearVelocity.Parent = HumRP
	
	local function GetDashVelocity()

		local vectorMask = Vector3.new(1, 0, 1)

		local direction = HumRP.AssemblyLinearVelocity * vectorMask

		if direction.Magnitude <= 0.1 then
			direction = HumRP.CFrame.LookVector * vectorMask
		end

		direction = direction.Unit
		local planeDirection = Vector2.new(direction.X, direction.Z)

		local dashVelocity = planeDirection * dashSpeed

		return dashVelocity
	end
	
	local function EnableLinearVelocity(dashVelocity: Vector2)

		linearVelocity.PlaneVelocity = dashVelocity
		linearVelocity.Enabled = true

		Hum.AutoRotate = false
		HumRP.CFrame = CFrame.new(HumRP.Position, Vector3.new(dashVelocity.X, 0, dashVelocity.Y) * 1000)
	end
	
	local function DisableLinearVelocity()

		linearVelocity.Enabled = false
		if hit == false then
			Hum.AutoRotate = true
		end

	end
	
	local dashVelocity = GetDashVelocity()
	
	local Hitbox = game.ReplicatedStorage.Quirks.ShigurakiAFO.Effects.Grab:WaitForChild("Hitbox"):Clone()
	Hitbox.Parent = game.Workspace
	Hitbox.CFrame = HumRP.CFrame
	game.Debris:AddItem(Hitbox,0.5)
	local weld = Instance.new("WeldConstraint", Hitbox)
	weld.Part0 = Hitbox
	weld.Part1 = HumRP
	
	local connection
	local starttime = os.clock()
	
	local alreadyHit = {}
	local HitboxOverlapsParam = OverlapParams.new()
	HitboxOverlapsParam.FilterType = Enum.RaycastFilterType.Exclude
	HitboxOverlapsParam.FilterDescendantsInstances = {Char}
	connection = RunService.Heartbeat:Connect(function(dt)




		local hitparts = workspace:GetPartsInPart(Hitbox, HitboxOverlapsParam)
		if #hitparts ~= 0 then
			if os.clock() >= starttime+1 then
				connection:Disconnect()
			end
			

			for i,v in pairs(hitparts) do
				if not table.find(alreadyHit,v) or table.find(alreadyHit,v.Parent) then
					local EHum = v.Parent:FindFirstChild("Humanoid")
					local EHumrp = v.Parent:FindFirstChild("HumanoidRootPart")



					if EHum and EHumrp then	


						if not table.find(alreadyHit,EHum) then

							table.insert(alreadyHit,EHum)
							
							hit = true
							
							DisableLinearVelocity()

							local Stun = Instance.new("BoolValue", Char)
							Stun.Name = "Stun"
							game.Debris:AddItem(Stun,2.3)
							
							local EStun = Instance.new("BoolValue", v.Parent)
							EStun.Name = "Stun"
							game.Debris:AddItem(EStun,2.3)


							hit = true
							EHum:TakeDamage(15)
							print("Hit")	
							
							Hum.AutoRotate = false
							EHum.AutoRotate = false
							
							game:GetService'RunService'.Heartbeat:Wait()
							HumRP.AssemblyLinearVelocity = Vector3.new(0, 0, 0)
							EHumrp.AssemblyLinearVelocity = Vector3.new(0, 0, 0)
							
							EHumrp.Anchored = true
							HumRP.Anchored = true
							
							HumRP.CFrame = EHumrp.CFrame * CFrame.Angles(0,math.rad(180),0) * CFrame.new(0,0,2)
							
							local Animator = Hum:FindFirstChildWhichIsA("Animator")
							local AnimID = game.ReplicatedStorage.Quirks.ShigurakiAFO.Animations:WaitForChild("GrabUser")
							local Anim = Animator:LoadAnimation(AnimID)
							Anim:Play()
							
							local EAnimator = EHum:FindFirstChildWhichIsA("Animator")
							local EAnimID = game.ReplicatedStorage.Quirks.ShigurakiAFO.Animations:WaitForChild("GrabVictim")
							local EAnim = EAnimator:LoadAnimation(EAnimID)
							EAnim:Play()
							
							local Part = game.ReplicatedStorage.Quirks.ShigurakiAFO.Effects.Grab:WaitForChild("Part"):Clone()
							Part.Parent = Char
							Part.CFrame = Char:WaitForChild("Right Arm").CFrame
							game.Debris:AddItem(Part,2)
							
							
							for i, b in pairs(Part:GetChildren()) do
								game.Debris:AddItem(b,2)
								if b:IsA("Attachment") then
									if b.Name == "B1" then
										b.Parent = Char:WaitForChild("Right Arm")
									elseif b.Name == "B2" then
										b.Parent = Char:WaitForChild("Right Arm")
									elseif b.Name == "B3" then
										b.Parent = Char:WaitForChild("Right Arm")
									elseif b.Name == "B4" then
										b.Parent = Char:WaitForChild("Right Arm")
									elseif b.Name == "B5" then
										b.Parent = Char:WaitForChild("Right Arm")
									elseif b.Name == "B6" then
										b.Parent = Char:WaitForChild("Right Arm")
									elseif b.Name == "B7" then
										b.Parent = Char:WaitForChild("Right Arm")
									elseif b.Name == "B8" then
										b.Parent = Char:WaitForChild("Right Arm")
									end
								end
							end
							
							for i, t in pairs(Part:GetChildren()) do
								game.Debris:AddItem(t, 2)
								if t.Name == "T1" then
									t.Parent = v.Parent:WaitForChild("Head")
									t.Position = Vector3.new(0,0,0)
									t.Orientation = Vector3.new(0,0,0)
								elseif t.Name == "T2" then
									t.Parent = v.Parent:WaitForChild("Head")
									t.Position = Vector3.new(0,0,0)
									t.Orientation = Vector3.new(0,45,0)
								elseif t.Name == "T3" then
									t.Parent = v.Parent:WaitForChild("Head")
									t.Position = Vector3.new(0,0,0)
									t.Orientation = Vector3.new(0,90,0)
								elseif t.Name == "T4" then
									t.Parent = v.Parent:WaitForChild("Head")
									t.Position = Vector3.new(0,0,0)
									t.Orientation = Vector3.new(0,135,0)
								elseif t.Name == "T5" then
									t.Parent = v.Parent:WaitForChild("Head")
									t.Position = Vector3.new(0,0,0)
									t.Orientation = Vector3.new(0,180,0)
								elseif t.Name == "T6" then
									t.Parent = v.Parent:WaitForChild("Head")
									t.Position = Vector3.new(0,0,0)
									t.Orientation = Vector3.new(0,225,0)
								elseif t.Name == "T7" then
									t.Parent = v.Parent:WaitForChild("Head")
									t.Position = Vector3.new(0,0,0)
									t.Orientation = Vector3.new(0,270,0)
								elseif t.Name == "T8" then
									t.Parent = v.Parent:WaitForChild("Head")
									t.Position = Vector3.new(0,0,0)
									t.Orientation = Vector3.new(0,315,0)
								end
							end
							
							task.wait(2.3)
							
							EHumrp.Anchored = false
							HumRP.Anchored = false
							Hum.AutoRotate = true
							EHum.AutoRotate = true
							
							local VeloCity = Instance.new("BodyVelocity",EHumrp)
							VeloCity.MaxForce = Vector3.new(60000,60000,60000)
							VeloCity.Velocity = HumRP.CFrame.LookVector * 60
							game.Debris:AddItem(VeloCity,0.6)
							
							
							
							
						end
					end
				end
			end
		end
	end)
	
	coroutine.wrap(function()

		EnableLinearVelocity(dashVelocity)
		
		task.wait(1)
		
		if hit == false then
	
			DisableLinearVelocity()
			print("DisabledCauseTheyMissed")
			
		end
		
	end)()
	
end)
1 Like

Update: So i fixed it, what I did was create two custom collision groups, set the player in one group, and all other models in the other group, and set the two groups to not collide with each other, once the player hit someone or the move ended, I unregistered the collision groups and it works perfect

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