Check distance

Get help using Construct 2

Post » Thu Dec 26, 2013 10:40 am

Hey, im working on a new game where u are in a space ship and need to destroy other ships. But i can't figure out how to check the distance between two sprites (I want the enemy shoot at the player if it's in range). How do i do that?

I hope someone can help me.
Image
B
13
S
2
G
1
Posts: 60
Reputation: 1,553

Post » Thu Dec 26, 2013 10:42 am

For each enemy
system compare two values: distance(player.x,player.y,enemy.x,enemy.y) < 100
- enemy shoot
I told my dentist I had trouble with my teeth and asked her to fix it without looking in my mouth..
B
54
S
16
G
8
Posts: 6,160
Reputation: 19,775

Post » Thu Dec 26, 2013 10:43 am

[QUOTE=LittleStain] For each enemy
system compare two values: distance(player.x,player.y,enemy.x,enemy.y) < 100
- enemy shoot[/QUOTE] Thanks, i will try.
[EDIT] Works! Thank you! I didn't know i had to use system!goodfeet2013-12-26 10:47:06
Image
B
13
S
2
G
1
Posts: 60
Reputation: 1,553

Post » Tue Jun 24, 2014 7:38 pm

this is a simple solution. thanks @littlestain
B
13
S
5
G
1
Posts: 119
Reputation: 2,292

Post » Tue Jun 24, 2014 8:12 pm

Just an extra to improve your coding...

Instead of 100 use a variable. In fact, I would use a Object Variable, that is, a variable in the enemy object, called "range" and compare distance to enemy.range, thus, you can even have different types of enemies with different ranges. :)
Bruno

I like to eat, but I'm no cook. Why liking to play games would make you a game designer?
B
19
S
5
G
2
Posts: 535
Reputation: 3,237


Return to How do I....?

Who is online

Users browsing this forum: Google [Bot], PROxMTswatTR and 41 guests