Impact

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

1 decade ago by ChrisC

Maybe I'm approaching this all wrong, so I'll post in here for any advice.

I have a side scroller cave adventure, with a little dwarf player. When he finds a battle axe, he is able to attack, and I have an axe swinging animation. When he swings the axe, the axe's range is outside of his own collision boundary.. so in order to get it to collide with an enemy I change his size.x while he is in the attack swing timeframe.

This works great to the right of the character, but to the left not so good - because it seems everything is positioned around the left side of him - so when he attacks right, his collision boundary juts out to the right and hits.. but on the left it doesn't, he appears to move back while his swing stays in exactly the same place, making it quite awkward to attack things to the left.

I hope this makes sense.

What I really need I guess is something a little more realistic, where the actual axe is an entity itself, and has its own collision area just to the left or right of the character, where when it collides with an enemy it somehow effects damage from the player towards the enemy.

Anyone know the best or better way to handle this?

thanks!

1 decade ago by manuelac

im an amateur but mabye something like

// in axe.js init function
this.pos.x = /* whatever you need */;
this.pos.y = /*whatever you need */;

// in axe.js update function
var player = ig.game.getEntitiesByType(EntityPlayer)[0];
if (player.touches(this)) {
  player.hasAxe = true;
}

if (player.hasAxe == true) {
  if (player.vel.x > 0) {
    this.pos.x = player.pos.x + /*offset axe to the right*/;
    this.pos.y = player.pos.y;
  } else if (player.vel.x < 0) {
    this.pos.x = player.pos.x - /*offset axe to the left*/;
    this.pos.y = player.pos.y;
  } else {
    this.pos.x = player.pos.x;
    this.pos.y = player.pos.y;
  }
} 

This code in the Axe entity would bound it to the position of the Player entity if the player picks it up. It also applies a desired offset to increase the range of the axe entity in both directions or keep it centered if the player is iddle.

I repeat that I suck at coding there is probably a million better ways to do this.

1 decade ago by Joncom

Maybe spawn a hit test entity when the player swings his axe:

ig.module('game.entities.hit-test')
.requires('impact.entity')
.defines(function() {

    EntityHitTest = ig.Entity.extend({

        size: { x: 16, y: 16 }, // Size of "hit area".

        init: function(x, y, settings) {
            this.parent(x, y, settings);

            // Loop through all enemies, and deal damage to any
            // that this entity is currently touching.
            var enemies = ig.game.getEntitiesByType(EntityEnemy);
            for(var i=0; i<enemies.length; i++) {
                if(this.touches(enemies[i])) {
                    dealDamageTo(enemies[i]);
                }
            }

            // Then kill this entity because it's no longer needed.
            this.kill();
        }
    });

});

1 decade ago by ChrisC

Thanks very much for your ideas. I will try out some solutions tonight.

Another idea I had was to fire a very short range invisible projectile, however since the axe swings over his head and then down, it would be nice if it effected entities above as well in the swing.

I also found another thread dealing with similar issues, for anyone reading this and looking for solutions to this as well:

http://impactjs.com/forums/help/melee-combat

1 decade ago by ChrisC

I am going to try something like Joncom suggested - since my weapons are not separate entities attached to the player with their own movements (like Terraria seems to do) and I just use a separate animation dependant on the weapon (because I think that looks better), its makes sense to spawn an invisible hit-test type entity.

Since the axe swings starting from above the player and then down to the side, I will spawn 2 of these, one rectangle above his head, and then one beside him - in succession (using the timer to time it with the swing, which I'm already using a timer for).

By the way I don't think you need to cycle through all the enemies and use the .touch function / deal damage.. since I'm spawning an entity, I just need to make it check against the enemy group (.B) and its check function can be used to deal the damage. Eg like in the jumpnrun demo:

	// This function is called when this entity overlaps anonther entity of the
	// checkAgainst group. I.e. for this entity, all entities in the B group.
	check: function( other ) {
		other.receiveDamage( 10, this );
		this.kill();
	}	

1 decade ago by Joncom

Quote from ChrisC
By the way I don't think you need to cycle through all the enemies and use the .touch function / deal damage.. since I'm spawning an entity, I just need to make it check against the enemy group (.B) and its check function can be used to deal the damage. Eg like in the jumpnrun demo
That's true. You can do it that way. I suppose you'll use a timer then, in the update method to kill the hit-test entity if it doesn't collide with an enemy after x time...

1 decade ago by ChrisC

Yep - I already have a timer going for the melee attack swing, for 0.25 s. So for the first half of that or so I'm spawning the hit check entity on the top, then for the 2nd half I remove it and spawn it at the side.

Don't know how well it works yet as I only have it about half done atm.

1 decade ago by ChrisC

Just to follow up on this - Everything went swimmingly, I am naming them meele, as they are a meele type attack check, so I can re-use them for any kind of hand held weapon attack.

One complication I didn't forsee is when the player is in motion, running right or left, falling or jumping - I had to add some code to make sure the meele entities stayed in place stuck to the player.
Page 1 of 1
« first « previous next › last »