@jurnacsr:
Are you sure that works?
It seems like it would work when facing right, but not when facing left.
1 decade ago
by lTyl
// Enemy.js
var player = ig.game.getEntitiesByType(EntityPlayer)[0],
xd = this.pos.x - player.pos.x,
yd = this.pos.y - player.pos.y,
distance = Math.sqrt(xd*xd + yd*yd);
Square Root isn't the fastest way of doing it, but it works...
@Joncom - you may be right. My geo/trig isn't really up to snuff, so maybe the angles would be off.
Could you take 45 degrees from the player's angle? As in, 45 deg +/- from the player's angle?
In fact, the more I think about it, my solution wouldn't work - it would assume that the player always faces right. You would have to test if the other entity's angle is within 45 degrees of the player's current angle.
Page 1 of 1
« first
« previous
next ›
last »