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 Dhoombaby

hi,
in my game my player shoots when i click shoot button , but i want the cops i.e enemy to fire when player is near to him but only in that direction ....my enemy is moving from left to right...so when player is on left side of him he should fire left..when player is right side of him he should fire right side...and only 3-4 bullets should come out...

i have applied logic..

if(this.distanceTo(ig.game.player) < 200 )
{
ig.game.spawnEntity( EntityBullet1, this.pos.x, this.pos.y+40, {flip:this.flip});
}

here problem i am facing is that when player is near to him he fires bullet but bullets comes out continuously till it kills player and and bullet fire only in one direction...so what is solution to this problem ?? i have stuck to it badly...can anyone help me?? reply urgently...

Thanks..

1 decade ago by stillen

You can use a timer to offset the bad guys fire action. Setting up timers were discussed here:

http://impactjs.com/forums/help/help-on-resetting-timers

Depending on the where the bad guy is in relation to your player, you can adjust the flip property:
http://impactjs.com/documentation/class-reference/animation#flip-x-flip-y

1 decade ago by Dhoombaby

Thanks Stillen...But now problem is that the enemy fire in wrong direction..means when player is moving right he fires in opposite direction...my question is that how to check the player and enemy are in opposite direction??

1 decade ago by Zoneh

If I were you I'd add "facingTo" property to enemies and the player. When you move your entity you should set facingTo to the proper value. Then check the property when shooting.

1 decade ago by Dhoombaby

Thanks Zoneh...but can it explore it more....
Page 1 of 1
« first « previous next › last »