Exact character collisions

Hello, my game uses a long leg as the base of this game I am making.

I want my legs to have better collisions and was wondering if there was a way to fix this…

Here’s a picture of what it looks like currently.

Pretty much I want it so if you’re on a side of a part it won’t just use the long leg’s collision box.

Edit:
Forgot to include the code that makes the leg long

local char = script.Parent

char["Right Leg"]:Destroy()
local leg = Instance.new("Part")
leg.Name = "Right Leg"
leg.Parent = char
char.Torso["Right Hip"].Part1 = leg
leg.Position = leg.Position - Vector3.new(0,2,0)
leg.Size = Vector3.new(1,6,1)
leg.Reflectance = 0.1
leg.Material = Enum.Material.SmoothPlastic
1 Like

I’m sorry, that I can’t give you the solution, but I can tell you the problem is probably the Humanoid Hip Height

1 Like

That would just lower my entire character.

I am looking for something like this, but you cant walk correctly with this.

local char = script.Parent

char["Right Leg"]:Destroy()
local leg = Instance.new("Part")
leg.Name = "RightLeg"
leg.Parent = char
char.Torso["Right Hip"].Part1 = leg
leg.Position = leg.Position - Vector3.new(0,2,0)
leg.Size = Vector3.new(1,6,1)
leg.Reflectance = 0.1
leg.Material = Enum.Material.SmoothPlastic

By removing the space in the name of the leg you’re able to have correct collisions.

Check: is right leg floating? If so, lower your hipheight. Otherwise, keep it normal.

Tried adding this, but it always says theres 0 touching parts

local char = script.Parent

char["Right Leg"]:Destroy()
local leg = Instance.new("Part")
leg.Name = "Right Leg"
leg.Parent = char
char.Torso["Right Hip"].Part1 = leg
leg.Position = leg.Position - Vector3.new(0,2,0)
leg.Size = Vector3.new(1,6,1)

game:GetService('RunService').Heartbeat:Connect(function()
	local touchingParts = leg:GetTouchingParts()
	
	print(#touchingParts)
	
	if #touchingParts == 0 then
		char.Humanoid.HipHeight = -4
	else
		char.Humanoid.HipHeight = 0
	end
end)

Use raycasts. Go from the center of the right leg, downwards, with half the leg length + 1 as the distance.

Raycast:
Origin: Right Leg
Direction: Down
Range: Half Leg Length + 1

What do you mean by Range? I looked in Raycasting | Documentation - Roblox Creator Hub, but I don’t see anything for range.

The range is just the length. Idk why I used a different word.

Ok, I’ve added the raycast code, but I’m getting a few issues.

@oddcraft18

local char = script.Parent

char["Right Leg"]:Destroy()
local leg = Instance.new("Part")
leg.Name = "Right Leg"
leg.Parent = char
char.Torso["Right Hip"].Part1 = leg
leg.Position = leg.Position - Vector3.new(0,2,0)
leg.Size = Vector3.new(1,6,1)

game:GetService("RunService").Heartbeat:Connect(function()
	local legPosition = leg.Position
	local legSize = leg.Size
	local halfLegLength = legSize.Y / 2
	local raycastDistance = halfLegLength + 1
	
	local raycast = workspace:Raycast(legPosition, Vector3.new(0, -100, 0))
	
	print(raycast.Distance)
	
	if raycast.Distance >= raycastDistance then
		char.Humanoid.HipHeight = -4
	else
		char.Humanoid.HipHeight = 0
	end
end)

It seems I can just walk through parts, until I jump.

Alright, I figured a way to kind of “hack” it.

local char = script.Parent

char["Right Leg"]:Destroy()
local leg = Instance.new("Part")
leg.Name = "Right Leg"
leg.Parent = char
char.Torso["Right Hip"].Part1 = leg
leg.Position = leg.Position - Vector3.new(0,2,0)
leg.Size = Vector3.new(1,6,1)

game:GetService("RunService").Heartbeat:Connect(function()
	local legPosition = leg.Position
	local bottomPosition = leg.Size - Vector3.new(0, leg.Size.Y / 2, 0)
	
	print(bottomPosition.Y)
	
	local raycast = workspace:Raycast(legPosition, Vector3.new(0, -100, 0))
	
	print(raycast.Distance)
	
	if raycast.Distance >= bottomPosition.Y + 1 then
		char.Humanoid.HipHeight = -4
		char["Right Leg"].CanCollide = true
	else
		char.Humanoid.HipHeight = 0
		char["Right Leg"].CanCollide = false
	end
end)

I made it so it will collide when the HipHeight is lowered to -4. It keeps it so you can’t walk into parts.

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