Hey All, Whenever I’ve made an action game with FlashPunk, or anything else for that matter, the only attack I’ve been able to make is a projectile through spawning another entity, say a rocket. Recently I’ve wanted to go into more combat than fire projectiles everywhere, meaning sword/melee combat similar to the original Zelda. And I wanted to try to do this without spawning a projectile that dies in quick succession. This problem has been stuck on my head for too long, so I thought I should bring it here for questions. Any help guys?
Melee Attack Collisions
You could have it where the collision entity is always there, but only checks for collision when a button is pressed or something rather than all the time. Just an idea. Something like:
if(Input.pressed(Key.X))
{
var e:Enemy = collide("enemy", x, y) as Enemy;
if(e)
{
e.doDamage();
}
}
Also you can define melee attack direction by using “x” “y” parameters in collide() condition.
The way it was done in the past was by synchronizing a hitbox with an attack animation.
I figured it was something like this, but was unsure how to go about it in Flashpunk. Maybe you could have an array of positions + hitbox sizes, that get updated every update, but was never really sure how to implement something like that, or if there was any other way. Also, that .gif explains it so much better then anything else I’ve found similar on the net. Will be great if I need to explain to others what I mean.
I use this in my current game. What I do is have an extra Hitbox in my entity class, and when checking for melee collisions I use hitbox.collide instead of the collide method.
You’ll need to position the hitbox manually each time, though. So yeah, an array or some simple data structure would work just fine.
How do you manage two hitboxes on the same entity? I didn’t think that was possible!
The player’s hitbox (green) is the one for collision with the player and is set with player.setHitbox()
. The attack hitbox (red) can be created dynamically and can still check for collisions with swordHitbox.collide()
(as @AbelToy mentioned).
Just make a new Hitbox
when you attack.
Multiple Hitboxes with different types
How do I have more than one Hitbox?
I tried this but the hitbox doesnt show up when i attack and when i assign it To my entity it drops off the entities nature hitbox. Do i have to create a seperate hitbox that replaces the standardhitbox the entity gets when created because i create additional masks at all?
I believe you can have multiple hitboxes (or masks of any kind) using a Masklist.
var myMaskList: Masklist = new Masklist(new Hitbox(blah), new Hitbox(blah);
player.mask = myMaskList;
Jep i unveiled that too but when i trigger the second hitbox(attack) it melts the hitboxes together to a huge rect - it doesnt handle them separately.
thats ok. but i want two different kind of collision with it too. so i guess is need a separate entity for this and then communicate with a set get function when it should popup and somehow allign it to the hero entity.
I use a similar technique in a new game I’m working on to allow for headshots. I have a separate ‘SpecialTarget’ entity that has its own hitbox and a callback for when it detects a collision. The ‘parent’ entity creates it and makes sure to keep its position up to date in it’s own update() function, then the ‘child’ entity calls a function in the parent entity when it detects a collision. This constructor for your child entity may help:
public function childEntity(parent: Entity, callback: Function)
{
_parentEntity = parent; //might be useful. You can for instance get the parent's x and y in update()
_collisionCallback = callback; //call this like this: if(callback != null) { callback(); } when a collission occurs
}
Not sure what’s going on with the syntax highlighting there.
That is weird. What name did you put for the language?
Using separate entities to represent different parts is something I do a lot. It’s very useful since a Masklist can’t have separate collision types.
I didn’t put a name, I just used the three ` thing around the block of text I wanted to be code. I was assuming it defaults to AS3…
Ah, no such luck I’m afraid. You have to put “actionscript” (no quotes) after the backticks for it to show up correctly. It usually doesn’t look that bad though.
I am working on a platformer fighting game, I would like to implement attack entities that check for collisions with enemies only when the attack button is pressed as mentioned above - I’m wondering if it would be more efficient to have a single attack entity for my player and just change the attack entity’s hitbox for different attacks, OR have a separate entity for each attack with unchanging hitboxes?
Any opinions or experiences?
Thanks,
How do you actually make the new hitboxes in the entity?
I know you make the original one with setHitbox, but if I want to make a new hitbox after the original one and name it, what do I type specifically?