How do I properly use hitbox on sword swing

Just started using Construct 2? Post your questions here

Post » Wed Feb 22, 2017 1:15 am

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 :D

http:// [Space] www. [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. 8-)
B
4
S
1
Posts: 5
Reputation: 310

Post » Wed Feb 22, 2017 1:50 am

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.
Banned User
B
23
S
6
G
58
Posts: 1,229
Reputation: 34,540

Post » Wed Feb 22, 2017 2:43 am

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.
B
4
S
1
Posts: 5
Reputation: 310

Post » Wed Feb 22, 2017 2:48 am

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!
B
4
S
1
Posts: 5
Reputation: 310

Post » Wed Feb 22, 2017 3:08 am

MagicCactus wrote: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!
Banned User
B
23
S
6
G
58
Posts: 1,229
Reputation: 34,540

Post » Wed Feb 22, 2017 3:39 pm

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.]
B
13
S
2
Posts: 6
Reputation: 637

Post » Fri Feb 24, 2017 11:31 pm

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. 8-)
B
4
S
1
Posts: 5
Reputation: 310

Post » Sat Feb 25, 2017 2:14 am

I'm glad you like it. I can try to answer if you have questions.
B
13
S
2
Posts: 6
Reputation: 637

Post » Sat Feb 25, 2017 5:59 pm

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
B
4
S
1
Posts: 5
Reputation: 310

Post » Sun Feb 26, 2017 5:12 am

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.
B
13
S
2
Posts: 6
Reputation: 637


Return to Beginner's Questions

Who is online

Users browsing this forum: No registered users and 4 guests