How to 'locate' an actor's X?

Posted:
Sat Jul 24, 2010 10:04 am
by NevenResnik
I have a cannon, a bullet, a timer when the actor shoots every 5 seconds, and an enemy. The enemy Is moving forward, and when the enemy enters the cannon's 'Sight range' the cannon starts shooting . Now, I thought that could be achieved with the enemy's X. My question is, how do I set up this rule, using the X of the enemy, so when the enemy enters the view actor, when it is in sight, that the cannon starts shooting, BUT ONLY if the enemy is aligned with the cannon.
Thanks!
Re: How to 'locate' an actor's X?

Posted:
Sat Jul 24, 2010 10:33 am
by DilloDude
You can do a check of the enemy's x and y values:
- Code: Select all
if (enemy.x < 320 && abs(enemy.y) < 20)
or something similar. However, if you have clones of your enemies, this won't work correctly. You'd need to store an array of all the enemies and loop through it or something like that. The alternative method is to use a separate actor as a 'sensor' - make it the right shape, and either just use a collision with an enemy, or check getAllActorsInCollision and loop throught to check if any of them are enemies.