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

Hi all,

I was wondering if anyone has come up with a reasonably well working implementation of a line of sight algorithm?

I thought I could implement this quickly with ig.game.collisionMap.trace() but since this only takes the collision map into account but not entities (i.e. doors) this is not the same.

Dominique
I dont suppose you could share any code you may have that worked? I'm looking to do the same kinda thing. :)
Quote from Hareesun
I dont suppose you could share any code you may have that worked? I'm looking to do the same kinda thing. :)

do you need an entity check?

i have made it with the trace statement:
```		// Get the x and y distance to the player
var xd = (ig.game.player.pos.x + ig.game.player.size.x / 2) - (this.pos.x + this.size.x / 2);
var yd = (ig.game.player.pos.y + ig.game.player.size.y / 2) - (this.pos.y + this.size.y / 2);

// Calculate the distance
this.distanceToPlayer = Math.sqrt(xd * xd + yd * yd);

// Check if the enemy has a line of sight to the player
// I working with a lot of entities, because of that i check how far away the entity is
if (this.distanceToPlayer < 500) {
var tr = ig.game.collisionMap.trace(this.pos.x + this.size.x / 2, this.pos.y + this.size.y / 2, xd, yd, 1, 1);

if (!tr.collision.x && !tr.collision.y) {
ig.log('I SEE YOU!!!!');
}
}
```
Page 1 of 1
« first « previous next › last »