How do I properly use hitbox on sword swing

0 favourites
  • 10 posts
From the Asset Store
The Stickman Sword is suitable for platformer / sidescrolling games
  • Please take a look at my CAPX file at the follow URL, I read that new people can't post links so I added "[Space]", that is not part of the link

    http:// [Space] [Space] filedropper [Space] .com/ [Space] meleeswordsquestion

    I have an animation that shows my player swinging a sword, during the animation I spawn a hitbox at the end of the sword using an ImagePoint. When the hitbox collides with the enemy it does damage. So I'm looking to figure out how when an animation goes off hitboxes spawn at the desired locations and in total they only hit the user once. Here are my issues.

    1) Using "On Key Press" the hitbox only spawn at the first frame of the animation. That doesn't do much for me.

    2) Using "On Key is Down" you can see the hitbox spawn at each point I wanted, that's great! The bad thing is 1 animation of the swing can hit the opponent 3 times which destroys him. Not to mention I don't want my users to have to hold down a button to do damage, they should be able to press a key once and see an ability happen that does damage.

    3) When all hit boxes spawn it kills the enemy by hitting him 3 times, I'd like the full animation to only hit once.

    I could just make one big hit box that spawns at the start of the animation but I feel like that wouldn't be the best way to do that. Having a hitbox at the end of the sword during its motions seems like the most authentic way to handle this, but I'm new to this and looking for help.

    Any advice/thoughts are welcome. Thanks in advance.

  • A hit box at the end animation or close to end would be more realistic and prevent multiple hits. You will just need it placed so it would contact the collision box of the enemies where it should.

  • Try Construct 3

    Develop games in your browser. Powerful, performant & highly capable.

    Try Now Construct 3 users don't see these ads
  • Thanks lamar,

    I used just one hitbox on the Animation frame 0 and moved it out a bit to where the sword extends on animation 2 and it seems to work pretty well. I'll continue using that, thanks for the advice.

  • I also made the hitbox a little wider and then when I spawned it I used the pin to pin it to the player so that if I'm running and attack it the hit registers. I'm golden now!

  • I also made the hitbox a little wider and then when I spawned it I used the pin to pin it to the player so that if I'm running and attack it the hit registers. I'm golden now!

    Right on!

  • www . filedropper . com / meleeswordanswer

    I forgot to enable dying for the enemy before uploading...

    Changes:

    C and B only work when he is playing the default animation

    Pressing C or B starts attack1 animation and spawns a hitbox object.

    Hitbox object has a variable called hitid. Default set to ",". Also it has fade (0.3 sec) attack animation takes 0.4 seconds(plus some delay)

    Hitbox is set to imagepoint1 every tick

    Upon collision it checks if ","&Enemy.UID&"," is a part of hitid if not it adds enemy.UID&"," to hit id and deals damage [shit. this part is wrong in the capx too. It works because there is one enemy but you have to fix it if you like this solution.]

  • Hey Cagtzn,

    That is an awesome CAPX! I think having that damage pop out of the character is extremely cool, plus your hitbox spawn is exactly what I was looking for. Thanks again for doing this, I haven't taken the time yet to analyze all your changes but wanted to say thanks. I'll have time to look over it later tonight or tomorrow.

  • I'm glad you like it. I can try to answer if you have questions.

  • Hey Cagtzn,

    After looking into the CAPX more i have two questions.

    1) In your changes you note "Hitbox is set to imagepoitn1 every tick". When I think of "Every Tick" I think of a System setting for every tick and I don't see that in the Event Sheet. So I'm just wondering where that is defined at.

    2) Is there an article or document you know of where I could learn more about the "find(Hitbox_Sword.hitid,","&Enemy.UID&",")" code you have for event 11 in the Event Sheet. I'm still trying to fully understand that. I saw you added "hitid" to the the Hitbox_Sword object and gave it the defautl value, but I don't understand the condition to check if the enemy player has that to or the Enemy.UID. When an object collides does that variable become a part of the other object? Anywhere I can get clarification would be greatly appreciated.

    Thanks for all your time, I'm learning a lot.

    Regards,

    MaticCactus

  • I1) You don't have to indicate "Every Tick". if conditions are met the event works, since on the 12th line there is no condition it will always work = every tick

    2) https://www.scirra.com/manual/126/system-expressions , as you can see find function returns -1 if it cannot find anything.

    Just click on Player from you Objects tab and change any value you want, it will be the default value.

    So how does it work? You seach if UID of the enemy is already written in your hitid variable(which is freshly created each time you swing your sword)

    As I told before the default is , because I'm always checking for ","&UID&","commas are important otherwise you can't differentiate between single, double or triple digits. That's why after a collision you add UID&"," instead of just UID

    , number1, number2, number3, number4,......(without space) as you can see now each number is enveloped.

    ps: UID is the unique id of an object, it's different(well unique :p) for each object so it is useful here.

Jump to:
Active Users
There are 1 visitors browsing this topic (0 users and 1 guests)