Alright, so I am working on implementing a punch function on my game, however, I am having some problems with the size of the Hitbox:
I’d want it to only cover the front of the player, however it automatically centers it. Even if I add a lookvector to the CFrame of the hitbox, it will still concentrate on the centre of the player (exact CFrame as HumanoidRootPart)
Here is the source that I have got for spawning the Hitbox in:
local Services =
{
Players = game:GetService('Players')
}
Services.Players.PlayerAdded:Connect(function(plr) plr.CharacterAdded:Connect(function(char)
local NewHitbox = Instance.new("Part")
NewHitbox.Parent = char
NewHitbox.Size = Vector3.new(5, 3.5, 2)
NewHitbox.CanCollide = false
NewHitbox.CastShadow = false
NewHitbox.CanQuery = false
NewHitbox.CanTouch = true
NewHitbox.Transparency = 1
NewHitbox.Name = 'HitBox'
local Weld = Instance.new('Weld')
local HRP : Part = char:FindFirstChild('HumanoidRootPart')
Weld.Parent = NewHitbox
Weld.Part0 = NewHitbox; Weld.Part1 = HRP
NewHitbox.CFrame = HRP.CFrame + HRP.CFrame.LookVector
end)
end)
Other than by welding the Hitbox to HumanoidRootPart, what are better ways of doing this without updating the CFrame via a loop?
Here’s an extra screenshot to better show how central the hitbox is:
Try increasing the size of the lookvector
HRP.CFrame.LookVector*hitbox.Size.Z/2
It’s only one stud length by default
3Ogre
(3Ogre)
April 19, 2022, 12:09pm
#4
2 Likes
Yes, I know the default is 1 stud and it is intentional, since that would already shift it forwards enough.
The issue may possibly be with the welding, but I am not aware of any other alternatives that don’t include using loops to correct the CFrame.
Oh wait just saw the weld, yeah that’s what is causing it to be centered.
I made a tutorial on how to visualize welds, tbh it’s the same as the new RigidConstraints so that’s another option
So yeah you can also edit the C0 or C1 as @3Ogre suggested.
2 Likes
Fixed it by adding one line:
Weld.C0 = CFrame.new(NewHitbox.CFrame.LookVector*Vector3.new(-1,-1,-1))
Now it’s working as intended:
Thanks to everyone that helped!
2 Likes
Also additional question that is a bit related, but I don’t want to make another topic for it:
How to parent character to a folder when it joins or respawned?
This is my current source:
local Services =
{
Players = game:GetService('Players')
}
Services.Players.PlayerAdded:Connect(function(plr)
if plr.Character then
plr.Character.Parent = workspace.Chars._inLobby
end
plr.CharacterAdded:Connect(function(char)
char.Parent = workspace.Chars._inLobby
end)
end)
3Ogre
(3Ogre)
April 19, 2022, 12:25pm
#9
When the character is created try waiting until it is added to the workspace then parent it to the folder
plr.CharacterAdded:Connect(function(char)
if not char:IsDescendantOf(workspace) then
repeat
task.wait()
until char:IsDescendantOf(workspace)
end
char.Parent = workspace.Chars._inLobby
end)
1 Like