How to 'locate' an actor's X?

Talk about making games.

How to 'locate' an actor's X?

Postby NevenResnik » Sat Jul 24, 2010 10:04 am

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!
NevenResnik
 
Posts: 42
Joined: Mon May 31, 2010 9:59 am
Score: 0 Give a positive score

Re: How to 'locate' an actor's X?

Postby DilloDude » Sat Jul 24, 2010 10:33 am

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.
Image
User avatar
DilloDude
 
Posts: 866
Joined: Tue Jan 24, 2006 9:51 am
Location: Nyerellion
Score: 58 Give a positive score


Return to Game Development

Who is online

Users browsing this forum: No registered users and 1 guest