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

R15 Punch Animation Collision Issue?

Asked by 6 years ago
Edited 6 years ago

Alright, so the title is self explanatory so the main issue is that the touched event isn't firing when one of three parts of an arm are touching a object.

So it's basic just a touched event and checking if it has a humanoid etc,. Nothing wrong there with the script. It's the actual collision detection with the arm and the part.

I don't want to move on to more risky methods(such as loops) without consultation from more experienced members.

If you want the script here is the pastebin (I know it's pretty bad it's just a draft script until I figure out what the problem is)

The event is firing I made it print, so put that off the list. The functions are being called so that is good.

Also to take note is the touched event rarely fires. I extended the "wait(.3)" time to see if it improves but it doesn't prove to be reliable. When I speak of unreliable I talk about where it has these gaps where it would stop working consistently for a certain amount of time before working again.

Unless I'm being a bit spoiled about how I want it to work I would like some advice on how to improve it to almost a 90% success rate of collision.

Thanks for reading and especially thanks if you decide to help out.

0
You can just use a code block, when you are writng your question :P mewant_taco 17 — 6y

1 answer

Log in to vote
1
Answered by 6 years ago

Alright, so my game itself has something similar. I won't be writing the whole script cause I'm at school but there are a few things you should know and label out.

  1. First think about how long your punch animation is. You wanna keep the animations all the same time length. For example, a right punch is 0.5 seconds, the left punch and left kick and right kick would have to be 0.5 seconds for it all to be smooth.

  2. Now you need some sort of way to detect if you are doing a left punch, a right punch, a left kick, or, a right kick.

  3. Now instead of using so many listeners, just use a table like so:

local LeftPunchParts = {
'LeftHand'
'LeftUpperArm'
'LeftLowerArm'
}

for _, Part in pairs(LeftPunchParts) do
    Char[Part].Touched:Connect(function(h)
        -- blah
    end)
end
  1. To set this fully up you will want a debounce and some variables
local TouchDebounce = true
local CurrentAction = nil
local plr = game.Players.LocalPlayer -- if local script
local Char = plr.Character or plr.CharacterAdded:Wait()

local LeftPunchParts = {
'LeftHand'
'LeftUpperArm'
'LeftLowerArm'
}

local RighPunchParts = {
'RightHand'
'RightUpperArm'
'RightLowerArm'
}

-- add tables for kicks if u want
local function CheckAction()
    -- here you shall determine what punch / kick it is
    CurrentAction = -- put current action here
end

UserInputService
    CheckAction() -- checking the action will set the CurrentAction var
    -- play animation
    if CurrentAction = 'Left Punch' then
        for _, Part in pairs(LeftPunchParts) do
            Char[Part].Touched:Connect(function(h)
                if TouchDebounce then
                    TouchDebounce = false
                    -- this will be leftarm
                    wait(0.5) -- seoncds of animation or cooldown
                    TouchDebounce = true
                end
            end)
        end
    end
end)

This should be your basic set up.

Hopefully this gave you an idea of what to do. Now I must go back to school.

Best of luck developer!

0
I will have a few issues with this scenario. I don't think you have noticed but the script I provided is a server script. I find it a bad habit to let the client send arguments to do damage to a player since it could be exploited. I do like the idea of using pairs for a list of names but it would be better if I could be able to disconnect the events. I will take a look into it. Thanks! GetGlobals 343 — 6y
0
U do notice there isn't much in terms of difference. Just put it in StarterCharacter, GetPlayerFromCharacter from a script. Next, you can use remote events. If the animation is playing then deal damage. BlackOrange3343 2676 — 6y
0
You shouldn't be thinking about exploits too much for now. Reasoning being u won't even know if u can get to the point where exploits become important BlackOrange3343 2676 — 6y
Ad

Answer this question