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 Donzo

Hello:

I'm making a spaceship game and am thinking of
implementing a heat-seeking or homing missile type projectile.

Basically it will lock in and go after enemies with some efficacy.

I'm sort of just pooling for thoughts on how such a logic might
be implemented in this engine, if it is possible.

How might one entity (A type)
locate the closest entity (B type)
and move toward it?

I suppose a similar logic might be applied to
an NPC character on auto-fight mode.

1 decade ago by Donzo

My current thoughts involve creating a
grid of invisible entities,

perhaps 4 or 8, though surround and travel with the missiles.
If enemies of B type check against any entities on the grid,
the grid will shut off and the missile will redirect to that position.

That might work.
Any better ideas?

1 decade ago by drhayes

That's a great idea to cut down on the number of distance checks.

You could then use distanceTo on Entity to figure out which enemy is closest to the missle.

1 decade ago by Donzo

Thanks,
I'll look into that.

1 decade ago by Donzo

I did it with a single targeting entity
linked to multiple missile entities.

When the targeting entity checks against anything other than bullets,
the missile locks on the enemy position.

EntityTarget = ig.Entity.extend({
	size: {x: 160, y: 160},
	offset: {x: 0, y: 0},
	maxVel: {x: 5000, y: 5000},
	friction: {x: 200, y: 200},
	type: ig.Entity.TYPE.NONE,
	checkAgainst: ig.Entity.TYPE.B, // Check Against B
	collides: ig.Entity.COLLIDES.NEVER,
	missile:null,
	
	
	update: function() {

		//Kill me 
		if (ig.game.missile == false ) {
			this.kill();
		}
		if (this.missile == 1) {
			var theMissile = ig.game.getEntityByName('missile');
		}
		else if(this.missile == 2){
			var theMissile = ig.game.getEntityByName('missileTwo');
		}
		if (theMissile != undefined){
			this.pos.x = theMissile.pos.x - (theMissile.size.x * 2);
			this.pos.y = theMissile.pos.y - (theMissile.size.y * 2);
		}
		
		this.parent();
	},
	
	
	check: function( other ) {
		if (other.name != "bullet"){
			if (this.missile == 1) {
				var theMissile = ig.game.getEntityByName('missile');
			}
			else if(this.missile == 2){
				var theMissile = ig.game.getEntityByName('missileTwo');
			}
			if (theMissile != undefined){
				theMissile.locked = true;
				theMissile.lockedTimer.set(.3);
				var angle = theMissile.angleTo( other );
				theMissile.storedX = Math.cos(angle) * theMissile.speed;
				theMissile.storedY = Math.sin(angle) * theMissile.speed;
				this.kill();
			}
		}
	}	
});
Page 1 of 1
« first « previous next › last »