How do I make a no-hit death?

Get help using Construct 2

Post » Tue Apr 19, 2016 10:00 am

So I want to add a mechanic that kills the player if they use a certain attack (say the Space button) and they don't hit anything, then , they should die.
B
25
S
6
G
4
Posts: 173
Reputation: 3,933

Post » Tue Apr 19, 2016 10:18 am

Event:

On Space Bar Pressed
&&
[INVERT] Attack is colliding with [FAMILY OR ENEMIES] Action: Set [Life Local Variable] to 0.


You can also set global variables such as:
"Special_Attack_Used = 0"

Event: 1. On Space Bar Pressed ; Action: Set Special_Attack_Used = 1


2. Event: Set Special_Attack_Used = 1

Sub-Event: 3. Attack is colliding with [FAMILY_OF_ENEMIES] Action: Destroy [FAMILY_OF_ENEMIES] ; Set Special_Attack_Used = 1


Sub-Event: 3. [INVERT] Attack is colliding with [FAMILY_OF_ENEMIES] Action: Set [Life] to 0.
Image Image Image
B
31
S
11
G
27
Posts: 748
Reputation: 17,093

Post » Tue Apr 19, 2016 10:28 am

this won't work.
since you set sub events - they will fire the same tick / next, and attacks animation won't end for let's say - 2.3 sec, and you don't know if it will hit, how long it flies and stuff. depends what kind of attack it is - melee or range?

the solution is next:
add local variable to attack named "didHit" with value 0.
when you activate the hit with some key (for example space) - set the animation on and wait till it ends. if it collided somewhere set didHit = 1.
once the animation ends - check if didHit is = 1, if it's 0 - kill player, otherwise don't do anything.

now this applies good for melee attacks, but what if you want a range projectile to check if it collided? add the same variable to the fired projectile.
on destroyed check if didHit is 0, if it is kill player, if not then nothing. ofcourse you will have to check if projectile collided and have a way to "terminate" projectile on miss... for example - starts with speed 400 and deceleration 100, after ~6seconds it will stop - therefore you destroy it when it reaches speed 0, which will trigger checking didHit. and ofcourse if collision happend you destroy it in that moment it hits (and set didHit to 1ofc)
Sea Monsters template - Isometric
Also includes 40 pages PDF of optimizations and "how-to" for your games, and how the "sea monsters" template was built. Follow link for details :)

sea-monsters-templates-and-assets_t162705
B
43
S
14
G
12
Posts: 626
Reputation: 9,450

Post » Tue Apr 19, 2016 10:29 am

You can also set the variable to that it's
EVENT: After [Special_Attack_Animation] has finished; ACTION: Set Special_Attack_Used = 1

Oh yeah you should consider what type of attack too. Thanks for that.

If it's melee then it should be safe to do that ^. I'm assuming sprite is destroyed immediately and no Impulse physics is applies to the Opponent after the attack.
Image Image Image
B
31
S
11
G
27
Posts: 748
Reputation: 17,093


Return to How do I....?

Who is online

Users browsing this forum: 25games, Ashley, mcscooter, TRMG and 33 guests

cron