This forum is read only and just serves as an archive. If you have any questions, please post them on

1 decade ago by Imran

I was toying around with entities today and one of the questions I had would be implementing some type of melee combat where, effectively, if a player hits a key when he's in close proximity to an enemy it triggers an animation of him using a knife/sword to kill an enemy.

Would it be better to use a separate entity (like EntitySlimeGrenade in the JumpNRun test) or should I edit the player entity to incorporate some kind of sword/collision switching.

Thanks in advance for any help guys!

1 decade ago by Ken

I would say making it part of the player entity. That just seems like a more simple solution. One issue I can see is it was a separate entity then you have to make sure that the position stays with the player who is striking. If player is moving while striking and say the browser is running a little choppy would that cause a disconnect? I don't know, just something to think about maybe.

But I'm brand new to Impact so ... :)

Good luck, hope you get your game built.

1 decade ago by Imran

Hey Ken - I actually did end up making part of the player entity, basically, what I did was defined a case where if a collisional was occurring with an enemy AND if the player had the melee button pressed, it would run a sword slash anim and take damage.

The one thing I need to figure out is the timing of the attack so that it's not a situation that can be button mashed.

1 decade ago by Ash_Blue

Hmm, thought about doing the collisions this way, but it won't work in some situations. The ideal way to do this would be creating a swing motion from 25 - 90 degrees with acceleration so the swing has a slight impact on enemies. This flash tutorial kind of had the right idea. Not too sure how to get the physics going with this for an attack though. If anyone figures out a code for this please post.

1 decade ago by Ash_Blue

Here is the best I could come up with for a sword weapon entity that goes with my character entity. If anybody has suggestions on how to make this better, I'm all ears.

// Inital swing to start entity
if( ig.input.pressed('swing') ) {
        var x = this.pos.x + (this.flip ? -40 : 40 );
	var y = this.pos.y + 15; EntityKatana, x, y, {flip:this.flip} );

EntityKatana = ig.Entity.extend({
	size: {x: 40, y: 15},
	maxVel: {x: 200, y: 200},
	type: ig.Entity.TYPE.NONE,
	checkAgainst: ig.Entity.TYPE.B, // Check Against B - our evil enemy group
	collides: ig.Entity.COLLIDES.PASSIVE,
	animSheet: new ig.AnimationSheet( 'media/katana.png', 40, 15 ),	
	init: function( x, y, settings ) {
		this.parent( x, y, settings );
		this.vel.x = (settings.flip ? -this.maxVel.x : this.maxVel.x);
		this.vel.y = 200;
		this.addAnim( 'idle', 0.2, [0] );
                this.swingTime = new ig.Timer(.1);
	handleMovementTrace: function( res ) {
		this.parent( res );
                if ( ( > 0) ) {
        check: function( other ) {
                other.receiveDamage( 10, this );
                if ( this.pos.x < other.pos.x ) {
                        other.vel.x = 50;
                else {
                        other.vel.x = -50; 
                other.vel.y = -100;


1 decade ago by Alex

I did it a different way. On attack, invisible entity bullet is fired for like 5pixels forward which then checks for collisions. Works for me, might not for you :)

1 decade ago by Ash_Blue

That's pretty much what I did here except it generates a block like a sword that moves down. There is some extra stuff too like creating the smash effect against enemies.

1 decade ago by Ash_Blue

Trying to get the character to stop in mid-air when the katana entity hits an enemy. Having trouble figuring out where to stick the gravity change for the character on the katana though. I know I need to adjust .gravityFactor to 0 and that would do it, but where to stick it?

This is the last piece I need to finish programming my Ninja Gaiden style sword combat!

1 decade ago by Ash_Blue

Figured it out. Needed an entity in the check function that activates a timer. Timer is then triggered in the update function to add a slight negative gravity factor.
Page 1 of 1
« first « previous next › last »