1 decade ago by fulvio
I have the following method inside my
I use it like the following:
EntityProjectile:
I then call the method within the
This works quite well, however I&
The desired outcome is displayed here in the absolutely incredible game by the name of The Iconoclasts when you're taking out bad guys.
The Iconoclasts Game Play
Notice how the angle of the projectile is always facing towards an enemy? That, my friends, is what I'm after! :P
There's also quite a few problems when two enemies are close to each other. The projectile just doesn't know which enemy to attract to considering I'm looping through every single enemy entity in the game. *ouch*
EntityProjectile
class:attractEntities: function(entityTypes) { for (var i = 0; i < entityTypes.length; i++) { // Get all entities of this type. var entities = ig.game.getEntitiesByType(entityTypes[i]); // Entities found. if (entities) { // All entities. for (var j = 0; j < entities.length; j++) { // Attract these entities. if (entities[j]) { var distance = this.distanceTo(entities[j]); var thisSizeX = 300; // this.size.x * 2; if (this.distanceTo(entities[j]) <= thisSizeX) { var angle = this.angleTo(entities[j]); this.currentAnim.angle = angle; this.vel.x = Math.cos(angle) * 20000; this.vel.y = Math.sin(angle) * 20000; } } } } } }
I use it like the following:
EntityProjectile:
attractedEntities: new Array(), init: function(x, y, settings) { this.parent(x, y, settings); // Entities to attract. this.attractedEntities.push(EntityBossEnemy); }
I then call the method within the
update()
method:update: function() { // Array of enemy entity types which will attract projectile. this.attractEntities(this.attractedEntities); this.parent(); }
This works quite well, however I&
039;m not convinced it's the best way of attracting the #EntityProjectile
towards an enemy Entity. I'm not getting the desired outcome I'm after unfortunately.The desired outcome is displayed here in the absolutely incredible game by the name of The Iconoclasts when you're taking out bad guys.
The Iconoclasts Game Play
Notice how the angle of the projectile is always facing towards an enemy? That, my friends, is what I'm after! :P
There's also quite a few problems when two enemies are close to each other. The projectile just doesn't know which enemy to attract to considering I'm looping through every single enemy entity in the game. *ouch*