Player wall collision

Hello!

So currently I’m working on a game exactly like those stickman episodes on youtube, but I encountered a problem though. Most of the times I would find a solution through forums or find a way to fix it, but I couldn’t find any.

Basically, I want the player to stop after it has hit the wall like in TSB. But it would just dismember the player apart. I tried deleting the velocity but it doesn’t work as I noticed it was already being deleted by the debris service. I also tried researching, but I couldn’t find any relating to it.

Video:

Code:

local function ragdoll(character,opponent_character)
--sets up the player so it can be fully ragdolled--
	for _,character_instances in opponent_character do
		if character_instances:IsA('BasePart') then
			
			character_instances.Anchored=false
			character_instances.Massless=true
			--[[character_instances.CollisionGroup='player_collidability'
			physics_service:CollisionGroupSetCollidable('player_collidability','Default',true)--]]

		end
		
		if character_instances.Name=="Humanoid" then
			
			character_instances.PlatformStand=true
			character_instances:ChangeState(Enum.HumanoidStateType.Ragdoll)
			
		end
	end
--welds the opponent to the player--
	for _,character_instances in opponent_character do
		if character_instances:IsA('BasePart') and character_instances.Name=='HumanoidRootPart' then

			local weld=Instance.new('Weld',character)

			weld.Part0=character:FindFirstChild('HumanoidRootPart')
			weld.Part1=character_instances
			weld.C1=CFrame.new(0,0,5)

			debris:AddItem(weld,.05)

		end
	end
	
	task.wait(.1)
--ragdolls the opponent--
	for _,root_part in opponent_character do
		if root_part.Name=='HumanoidRootPart' then

			root_part.CFrame=CFrame.lookAt(root_part.CFrame.Position,character:FindFirstChild('HumanoidRootPart').CFrame.Position)
			character:FindFirstChild('HumanoidRootPart').CFrame=CFrame.lookAt(character:FindFirstChild('HumanoidRootPart').CFrame.Position,root_part.CFrame.Position)

			local attachment_0=Instance.new('Attachment',root_part)

			local linear_velocity=Instance.new('LinearVelocity',root_part)

			linear_velocity.Attachment0=attachment_0
			linear_velocity.MaxForce=math.huge
			linear_velocity.VectorVelocity=root_part.CFrame.LookVector*-500+root_part.CFrame.UpVector*200-ragdoll force

			for _,joint in opponent_character do
				if joint:IsA('Motor6D') then

					joint.Enabled=false

					local socket=Instance.new('BallSocketConstraint',joint.Parent)

					local attachment_1=Instance.new('Attachment',joint.Part0)

					local attachment_2=Instance.new('Attachment',joint.Part1)

					linear_velocity.MaxForce=math.huge
					attachment_1.CFrame=joint.C0
					attachment_2.CFrame=joint.C1
					socket.Attachment0=attachment_1
					socket.Attachment1=attachment_2
					socket.LimitsEnabled=true
					socket.TwistLimitsEnabled=true

					debris:AddItem(attachment_0,.5)
					debris:AddItem(linear_velocity,.5)
					debris:AddItem(socket,2.5)

				end
			end
		end
	end

	task.wait(2)
--resets the opponent--
	for _,character_instances in opponent_character do
		if character_instances:IsA('BasePart') then

			if character_instances.Name=='HumanoidRootPart' then character_instances.Anchored=false end
			
			character_instances.Massless=false
			--character_instances.CollisionGroupId=0

		end
		
		if character_instances:IsA('Motor6D') then
			
			character_instances.Enabled=true
			
		end
		

		if character_instances.Name=="Humanoid" then

			character_instances.PlatformStand=false
			character_instances:ChangeState(Enum.HumanoidStateType.GettingUp)

		end
	end
	return
end

Any help would be appreciated!

what if setting assembly liner velocity and assembly anuglar velocity to vector 3(0, 0, 0) and then deleting the forece if it exists

1 Like

Sorry for the late reply.

But do you mean that I should make a new velocity whenever the opponent hits the wall? Could you provide a little bit more detail.

1 Like

Hi! I think you can do that with Raycast and TweenSevice
Like at this algorithm:
Player punch dummy > Raycast to punch direction > Get Raycast result > Tween dummy to result position. And if raycast result if false (no wall) then tween dummy on some distantion, like 100 studs

1 Like

There is one simple solution, raycast
Whenever you want to detect something, always use raycast.

You can combine this with heartbeat service so that the raycast will be created for every fps to ensure accuracy

1 Like

Thanks for the reply!

I will be looking into it, although I’m confused if I should make a corountine that creates a raycast whenever the function runs or make the raycast whenever the script detects the opponent to be in a ragdoll state.

I don’t think tweening my opponent to a designated or a random spot of the map would look like an ideal fighting game. Raycasting looks like a better solution and I will be implementing it into my code!

Its really difficult when the opponent launches 500 studs away lol.

No need for a couroutine, an event is technically one

1 Like

It worked! It’s very buggy though since I’m casting the ray from the HumanoidRootPart’s lookvector but a simple fix I made is creating a hitbox around the opponent which detects if there is a collision! I appreciate for your help as if I didn’t use the run service, none of this would work. Thank you again!

1 Like

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