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 Jastro

Its possible to create a function for entities like check(other), but this function its "seen" when the entity see other entitie do something

Seen (other){
	if(other.name == pj){
		do something!
	}
}

Like this!!! Its possible? :D

1 decade ago by dominic

You could do a trace on the collision map from one entity to another. If the trace does not collide with the collision map, they can see each other.

E.g., if you want to check in an enemy entity if it can see the player entity:
update: function() {
	var player = ig.game.player;
	var res = ig.game.collisionMap.trace( 
		this.pos.x, this.pos.y, // start
		this.pos.x - player.pos.x, this.pos.y - player.pos.y, // dir
		1, 1 // size
	);
	
	if( !res.collision.x && !res.collision.x && !res.collision.slope ) {
		// this entity can see the player
	}
	
	this.parent();
},

(This assumes that you saved a reference to the player entity in ig.game and that the game has a CollisionMap)

1 decade ago by Datamosh

Great snippet! ;)

1 decade ago by alexandre

+ 1
Page 1 of 1
« first « previous next › last »