Enemy attacking range

Get help using Construct 2

Post » Tue Oct 16, 2012 8:09 pm

Hi, I have created an enemy.. got the enemy patrolling using edge markers, but I am unable to figure out how to get the enemy to fire if the player comes within a certain range of the enemy (line of sight kinda)

The enemy shoots only on the X-axis while facing the Player.
So, I wanted to know how to make the enemy fire at the player when the player reaches within certain pixels(?) of the enemy.
Thanks!
B
5
S
1
Posts: 38
Reputation: 839

Post » Tue Oct 16, 2012 9:24 pm

Use the distance() expression.
B
90
S
30
G
24
Posts: 3,189
Reputation: 32,400

Post » Wed Oct 17, 2012 8:49 am

Hi, I still was not able to get it right... can anyone give me a sample on how to use it? I dont think I am doing it the right way too.
I have put instance variables (oldx and oldy) to player as well as the enemy. I have set values:
PlayerBox: On Created -> Set oldx to PlayerBox.X
                      -> Set oldy to PlayerBox.Y
And the same for enemy too.
After this I dont know how to compare distances between the two objects. :( The distance says I have to input 4 values, whereas I just need to see if the distance between the two on X axis.
Please help :)

Thanks!
B
5
S
1
Posts: 38
Reputation: 839


Return to How do I....?

Who is online

Users browsing this forum: Kagubro and 17 guests