Scripting Helpers is winding down operations and is now read-only. More info→
Ad
Log in to vote
0

How can I make my hitbox more accurate?

Asked by 4 years ago

I've been working to find the most accurate hit box I can find. There is Region3,magnitude and raycasting. I chose Region3 cause it's the most simplest. I have a video of the combat system here. Red Boxes are the hitboxes

It's basically a 4 way combo system with things like damage indicators. Damage Indictors,Stamina and stun All work perfectly except the accuracy of the hitboxes. Basically what i'm trying to say is that sometimes the hitbox will hit other hitboxes,the ground or even me and the whole attack will get fallen off.(because I use debounces) I haven't really found any other explanation as to why region3 script wouldn't be working but if there is any reason please tell me. This is my first combat system so any advice would be appreciated.

Local Script Only used to access the player and prevent some client to server hacking

---script is pureply to get the player(Player stats)

script.Parent.Activated:Connect(function()
    game.ReplicatedStorage.StaminaRem.ARemote:FireServer()
end)

Server Script

Tool = script.Parent
char = script.Parent.Parent.Parent.Character
local ten = true
local en = true
local TweenService = game:GetService("TweenService")
local Player = game.Players.LocalPlayer
local swinging = false
local on = 1
local running = false
local timer = tick()
--Orginal -- 4,0,1.5,0
--Small -- 1,0,0.5,0

local function newhitbox()
    --Right Arm HitBox
    local RAhitbox = Region3.new(Vector3.new(0, 0, 0),Vector3.new(2, 2.5, 2))
    local Hhitbox = Region3.new(Vector3.new(0, 0, 0),Vector3.new(2, 2, 2))
    local RA = Instance.new("Part")
    game:GetService("Debris"):AddItem(RA,0.5)
    RA.Parent = char
    RA.Name = "RA"
    RA.Anchored = false
    RA.Size = RAhitbox.Size
    RA.CanCollide = false
    RA.Transparency = 0.5
    RA.BrickColor = BrickColor.new("Really red")
    RA.CFrame = char["Right Arm"].CFrame
    RA.BottomSurface = "Smooth"
    RA.TopSurface = "Smooth"
    local weld = Instance.new("Weld")
    weld.Part0 = char["Right Arm"]
    weld.C0 = char["Right Arm"].CFrame:inverse()
    weld.Part1 = RA
    weld.C1 = RA.CFrame:inverse()
    weld.Parent = RA
    RA.Anchored = false
    --Left Arm HixBox
    local LAhitbox = Region3.new(Vector3.new(0, 0, 0),Vector3.new(2, 2.5, 2))
    local LA = Instance.new("Part")
    game:GetService("Debris"):AddItem(LA,0.5)
    LA.Parent = char
    LA.Name = "LA"
    LA.Anchored = false
    LA.Size = LAhitbox.Size
    LA.CanCollide = false
    LA.Transparency = 0.5
    LA.BrickColor = BrickColor.new("Really red")
    LA.CFrame = char["Left Arm"].CFrame
    LA.BottomSurface = "Smooth"
    LA.TopSurface = "Smooth"
    local weld = Instance.new("Weld")
    weld.Part0 = char["Left Arm"]
    weld.C0 = char["Left Arm"].CFrame:inverse()
    weld.Part1 = LA
    weld.C1 = LA.CFrame:inverse()
    weld.Parent = LA
    LA.Anchored = false
    --Left Leg
    local LLhitbox = Region3.new(Vector3.new(0, 0, 0),Vector3.new(2, 2.5, 2))
    local LL = Instance.new("Part")
    game:GetService("Debris"):AddItem(LL,0.5)
    LL.Parent = char
    LL.Name = "LL"
    LL.Anchored = false
    LL.Size = LLhitbox.Size
    LL.CanCollide = false
    LL.Transparency = 0.5
    LL.BrickColor = BrickColor.new("Really red")
    LL.CFrame = char["Left Leg"].CFrame
    LL.BottomSurface = "Smooth"
    LL.TopSurface = "Smooth"
    local weld = Instance.new("Weld")
    weld.Part0 = char["Left Leg"]
    weld.C0 = char["Left Leg"].CFrame:inverse()
    weld.Part1 = LL
    weld.C1 = LL.CFrame:inverse()
    weld.Parent = LL
    LL.Anchored = false
    --Right Leg
    local RLhitbox = Region3.new(Vector3.new(0, 0, 0),Vector3.new(2, 2.5, 2))
    local RL = Instance.new("Part")
    game:GetService("Debris"):AddItem(RL,0.5)
    RL.Parent = char
    RL.Name = "RL"
    RL.Anchored = false
    RL.Size = RLhitbox.Size
    RL.CanCollide = false
    RL.Transparency = 0.5
    RL.BrickColor = BrickColor.new("Really red")
    RL.CFrame = char["Right Leg"].CFrame
    RL.BottomSurface = "Smooth"
    RL.TopSurface = "Smooth"
    local weld = Instance.new("Weld")
    weld.Part0 = char["Right Leg"]
    weld.C0 = char["Right Leg"].CFrame:inverse()
    weld.Part1 = RL
    weld.C1 = RL.CFrame:inverse()
    weld.Parent = RL
    RL.Anchored = false
    --Head

    local H = Instance.new("Part")
    game:GetService("Debris"):AddItem(H,0.5)
    H.Parent = char
    H.Name = "H"
    H.Anchored = false
    H.Size = Hhitbox.Size
    H.CanCollide = false
    H.Transparency = 0.5
    H.BrickColor = BrickColor.new("Really red")
    H.CFrame = char["Head"].CFrame
    H.BottomSurface = "Smooth"
    H.TopSurface = "Smooth"
    local weld = Instance.new("Weld")
    weld.Part0 = char["Head"]
    weld.C0 = char["Head"].CFrame:inverse()
    weld.Part1 = H
    weld.C1 = H.CFrame:inverse()
    weld.Parent = H
    H.Anchored = false


    --Touched Event--Right Arm
    RA.Touched:Connect(function(hit)
        local tweenInfo1 = TweenInfo.new(0.1,Enum.EasingStyle.Quad,Enum.EasingDirection.Out,0,false)
        local tweenInfo2 = TweenInfo.new(0.2,Enum.EasingStyle.Quad,Enum.EasingDirection.Out,0,false)
        local tweenInfo3 = TweenInfo.new(0.5,Enum.EasingStyle.Quad,Enum.EasingDirection.Out,0,false)
        if on == 1 then
local   touching = char.RA:GetTouchingParts()
for i,v in pairs(touching) do
    if not ten then return end
    if not swinging then return end
    ten = false
    local hum = char.Humanoid 
    if hit.Parent:FindFirstChild("Humanoid") and on == 1 then
        print("hit 1")
        script.Parent.Hit:Play()
        hit.Parent:FindFirstChild("Stun").Value = true
        local ehum = hit.Parent:FindFirstChild("Humanoid")
        local anim = ehum:LoadAnimation(Tool.StunRight)
        anim:Play()
        --Opponet moving--
        local eroot = hit.Parent:FindFirstChild("HumanoidRootPart")
        local bv = Instance.new("BodyVelocity",hit.Parent.Torso)
    game:GetService("Debris"):AddItem(bv,0.1)
    bv.MaxForce = Vector3.new(math.huge,math.huge,math.huge)
    bv.Velocity = char.HumanoidRootPart.CFrame.LookVector*11
    --
         hit.Parent.Humanoid:TakeDamage(char.StrengthF.Value * 3 / 2)
        local DI = game.ReplicatedStorage.Parts.DI:Clone()
        game:GetService("Debris"):AddItem(DI,0.7)
        local tween1 = TweenService:Create(DI.DamageBill,tweenInfo1,{Size = UDim2.new(4,0,1.5,0)})
        local tween2 = TweenService:Create(DI.DamageBill.Frame.DamageText,tweenInfo2,{TextTransparency = 1})
        local tween4 = TweenService:Create(DI,tweenInfo3,{CFrame = hit.Parent:FindFirstChild("HumanoidRootPart").CFrame * CFrame.new(math.random(-4,4),3,0)})
        local tween3 = TweenService:Create(DI.DamageBill.Frame.DamageText,tweenInfo2,{TextStrokeTransparency = 1})
        tween1:Play()
        tween4:Play()
        DI.CanCollide = false
        DI.Anchored = true
        DI.Parent = workspace
        DI.CFrame = hit.Parent:FindFirstChild("HumanoidRootPart").CFrame
        DI.DamageBill.Frame.DamageText.Text = char.StrengthF.Value * 3 / 2
        wait(0.5)
        tween2:Play()
        tween3:Play()
        hit.Parent:FindFirstChild("Stun").Value = false
    end
end
end
end)

end

game.ReplicatedStorage.StaminaRem.ARemote.OnServerEvent:Connect(function(Player)
    local tweenInfo1 = TweenInfo.new(0.2,Enum.EasingStyle.Quad,Enum.EasingDirection.Out,0,false)
    if en == false then return end
    if char.Stun.Value == false then
    en = false
    local Wave = game.ReplicatedStorage
    if tick()-timer > 0.6 then
        on = 1
    end
    newhitbox()
    local root = char:FindFirstChild("HumanoidRootPart")
    local bp2 = Instance.new("BodyVelocity",char.Torso)
    game:GetService("Debris"):AddItem(bp2,0.1)
    bp2.MaxForce = Vector3.new(math.huge,math.huge,math.huge)
    bp2.Velocity = root.CFrame.LookVector*10
    if char.Humanoid.WalkSpeed ~= 16 then
        running = true
    else
        running = false
    end
    script.Parent.Miss:Play()
    timer = tick()
    local char = Tool.Parent
    local hum = char:WaitForChild("Humanoid")
    local anim = hum:LoadAnimation(script.Parent["Animation"..on])
    anim:Play()
    swinging = true
    if running == true then
         char.Humanoid.WalkSpeed = 0
    else
        char.Humanoid.WalkSpeed = 1
    end
    if on == 4 then
        print("on = 4")
        for i = 1,6 do
            wait(0.1)
            char.Humanoid.WalkSpeed = 0
        end
    end
    wait(0.3)
    ten = true
    if running == true then
        char.Humanoid.WalkSpeed = Player.Stats.Agility.Value * 0.4 + 16
    else
        char.Humanoid.WalkSpeed = 16
end
    on = on + 1
    if on >= 5 then
        on = 1
        wait(0.6)
    end
    en = true
    swinging = false
    end
end)


Regards, Bl_ueHistor

Answer this question