So I was trying to create a hitbox around a custom npc (for whatever reason) in a project, but GetBoundingBox is not working the way I’m expecting it.
Issue: The part created with the values GetBoundingBox returns is innaccurate to the model’s actual size. I doubt this is a bug because usually when something doesn’t work for me I’m just bad at using it.
The NPC:
Said character’s hitbox looks normal in studio (is a model)
My code:
local hitbox = Instance.new("Part", person)
hitbox.Transparency = 1
local cf : CFrame, size : Vector3 = person:GetBoundingBox()
hitbox.CFrame = cf
hitbox.Size = size
hitbox.Anchored = true
hitbox.CanCollide = false
print(cf.Position)
print(size)
-- Weld --
local newWeld = Instance.new("WeldConstraint", person)
newWeld.Part0 = person.Torso
newWeld.Part1 = hitbox
In this scenario, “person” is the model in question: shown in picture 1, and said model’s torso is the character’s main body, as shown in picture 1.
End result after running code:
The hitbox created with the code far overlaps the actual character. I’m trying to figure out how I can fix this. Any help would be appreciated. Thanks for reading.