How to make hitbox consistent?

Hello! Im making a fighting game and i am trying to make the hitboxes work. Right now, the hitbox spawns and deals damage like it should be, but it’s position varies everytime the player turns.

Any reason why this is happening?

local function newHitBox(character, size, offset, damage, linger)
	local hrp = character:FindFirstChild("HumanoidRootPart")
	if hrp == nil then
		return
	end
	local weld = Instance.new('WeldConstraint', hrp)
	local hitbox = Instance.new('Part')
	weld.Part0 = hrp
	weld.Part1 = hitbox
	hitbox.CanCollide = false
	hitbox.CanQuery = false
	hitbox.Massless = true
	
	hitbox.Size = size
	hitbox.CFrame = hrp.CFrame + Vector3.new(offset.X, offset.Y, offset.Z)
	hitbox.Parent = character

The problem is that you are not adjusting the offset of your hitbox based on the rotation of your character. Keep in mind I haven’t tested the code below but it should work.

hitbox.CFrame = hrp.CFrame + hrp.Cframe:vectorToWorldSpace(Vector3.new(offset.X, offset.Y, offset.Z))

hrp.Cframe:vectorToWorldSpace() adjusts the local world offset you defined based on the rotation of the humanoidRootPart.

2 Likes

The issue still persists even with this.

1 Like

Fixed it by just switching VectorToObjectSpace to VectorToWorldSpace

2 Likes

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