The Daily Click ::. Forums ::. Klik Coding Help ::. Enemy zone
 

Post Reply  Post Oekaki 
 

Posted By Message

jbjovi



Registered
  22/07/2007
Points
  41
19th May, 2008 at 04:27:26 -

Hello everybody,

I'm stuck wih a problem with my project (again ).

I have an object (enemy), and I want it to shoot at the player when he's in a defined zone around the enemy.

I can easyly do it if there's only one enemy, but if I copy the object to have multiples enemys on my frame, nothing works. I could do it using another object representing the zone for each object but this means that it's necessary to code for every enemy on the frame. And I'm sure there's an easyer way to do it.

So if you know how to do that, please, let me know.

Hope you'll understand and sorry for my languages mistakes, I'm french.

 
n/a

Assault Andy

Administrator
I make other people create vaporware

Registered
  29/07/2002
Points
  5686

Game of the Week WinnerVIP Member360 OwnerGOTM JUNE - 2009 - WINNER!GOTM FEB - 2010 - WINNER!	I donated an open source project
19th May, 2008 at 04:36:08 -

One way you could do it is to always set an alterable value of an enemy to the distance between it and the player. This could be done with maths or with an extension. This distance would be different for every enemy as it is an internal value.

All you would need to do next is check whether the alterable value of an enemy was less than a certain value (eg: 200 pixels) and then make it attack the player.

 
Creator of Faerie Solitaire:
http://www.create-games.com/download.asp?id=7792
Also creator of ZDay20 and Dungeon Dash.
http://www.Jigxor.com
http://twitter.com/JigxorAndy

jbjovi



Registered
  22/07/2007
Points
  41
19th May, 2008 at 05:13:25 -

The way I have tried is not far from your suggestion, but I'm gonna try yours immediatly and I'm sure it will work, so thank you very much.

 
n/a

jbjovi



Registered
  22/07/2007
Points
  41
19th May, 2008 at 05:13:27 -

Just to let you know that it work fine, so thank you again. I've added some restrictions so it can't shoot if he's dying or if it isn't in front of the player. Now all works fine.

Image Edited by the Author.

 
n/a

Ski

TDC is my stress ball

Registered
  13/03/2005
Points
  10130

GOTW WINNER CUP 1!GOTW WINNER CUP 2!GOTW WINNER CUP 3!KlikCast HelperVIP MemberWii OwnerStrawberryPicture Me This Round 28 Winner!PS3 OwnerI am an April Fool
Candy Cane
19th May, 2008 at 06:49:33 -

Just use the Advanced direction object to compare distances?

 
n/a

Joe.H

Evil Faker

Registered
  19/08/2002
Points
  3305
19th May, 2008 at 08:20:22 -

Oui, le francais est tres populaire en France

 
My signature is never too big!!!

jbjovi



Registered
  22/07/2007
Points
  41
19th May, 2008 at 08:49:10 -

Tout à fait, c'est même la langue que j'utilise le plus à vrai dire !

 
n/a

jbjovi



Registered
  22/07/2007
Points
  41
19th May, 2008 at 08:51:36 -


Originally Posted by -Adam-
Just use the Advanced direction object to compare distances?



I prefer to code that kind of things by myself cause the more I code, the more I get control on what I do.

 
n/a

wizkidweb



Registered
  11/12/2007
Points
  143
19th May, 2008 at 11:54:07 -

Well, you could use Spread Values...

 
When you do things right, people won't be sure you've done anything at all.
- God (Futurama)

jbjovi



Registered
  22/07/2007
Points
  41
19th May, 2008 at 13:25:02 -


Originally Posted by wizkidweb
Well, you could use Spread Values...



I've never worked on this, is there a tutorial somewhere explaining what it is and how to use it ? Maybe I could use it for something else.

EDIT : Forget it, I have looked in MMF help. This thing could be really usefull, thanks for the tips.

Image Edited by the Author.

 
n/a

Knudde (Shab)

Administrator
Crazy?

Registered
  31/01/2003
Points
  5125

Has Donated, Thank You!Clickzine StaffKlikCast StarVIP MemberGhostbuster!Dos Rules!I donated an open source project
20th May, 2008 at 01:23:32 -

Geez you guys make this harder on yourselves. Just switch the order of objects in your condition.

X position of [Enemy] > Player - [Range in pixels]

^ That one works properly with multiple enemies

V This one does not.

X position of [Player] > [Enemy] - [Range in pixels]

So basically, don't check the position of the player, check the position of the enemy (which runs through every enemy every loop).

 
Craps, I'm an old man!

jbjovi



Registered
  22/07/2007
Points
  41
20th May, 2008 at 02:07:24 -

Does your method works if I test X AND Y ? What I mean is, I want the enemy to shoot at the player if :

- Is in the direction of player
- Player is in a range of + or -250 pixels (depending on the position of player relative to the enemy) from the enemy (X axis)
- Player is in a range of -10 to +10 pixels from the enemy (Y axis)

What I want to simulate is some sort of range of view but as the enemy is constantly moving...

Don't bother too much, now it works with the method given by Assault Andy.

 
n/a

Cecilectomy

noPE

Registered
  19/03/2005
Points
  305

Has Donated, Thank You!VIP MemberWeekly Picture Me This Winner!Cardboard BoxGhostbuster!Pokemon Ball!ComputerBox RedSanta HatSnowman
I am an April Fool
20th May, 2008 at 07:43:33 -

sadly shabs only works for the x distance. but can be modified slightly to work in an x AND y situation.

dont use

- Player is in a range of + or -250 pixels (depending on the position of player relative to the enemy) from the enemy (X axis)
- Player is in a range of -10 to +10 pixels from the enemy (Y axis)

because that makes a square which doesnt accurately depict distance. the enemy could be +10 and 250 away which is farther than 0 and 250. its just not good practice.

use a distance formula to put the distance of the enemy from the player into an alterable.

distance^2 = x^2 + y^2

distance = sqrt(x^2 + y^2)

x would be the x distance between enemy and player, and y would be y distance between enemy and player. that formula gives you the distance in between based on their x's and y's.

simply compare the distance to a fixed value to check if its close enough.

 
n/a

jbjovi



Registered
  22/07/2007
Points
  41
20th May, 2008 at 14:52:35 -

What I've done is really near of what you are saying, if I understand you well.

What I'm doing is :

- Compare x position of player and enemy and store it in an alterable value.
- Do the same with Y position and store it in another alterable value.

Then, all I have to do is :

If X position of player greater than a defined value relative to enemy
And X position of player lower than a defined value relative to enemy
And Direction of enemy is in front of player
Then shoot in Direction of player

Obviously, I have added the same for Y in the same event so enemy can only shoot player if their Y position are almost the same

This event has two adventages. First, as I'm having multiple same enemies in a scene, every enemy will react differently depending on the two alterable values stored. And the other advantage is that it can easeyly be modified for other enemies if I want them to react differently.

Image Edited by the Author.

 
n/a

Cecilectomy

noPE

Registered
  19/03/2005
Points
  305

Has Donated, Thank You!VIP MemberWeekly Picture Me This Winner!Cardboard BoxGhostbuster!Pokemon Ball!ComputerBox RedSanta HatSnowman
I am an April Fool
20th May, 2008 at 15:32:28 -

i understand what you are doing but its not mathematically correct. comparing the x independantly from the y makes the attack zone a square. you have to use x and y together in that formula to make the zone circular

Image

Image Edited by the Author.

 
n/a

Knudde (Shab)

Administrator
Crazy?

Registered
  31/01/2003
Points
  5125

Has Donated, Thank You!Clickzine StaffKlikCast StarVIP MemberGhostbuster!Dos Rules!I donated an open source project
20th May, 2008 at 15:57:03 -


Originally Posted by cecil
sadly shabs only works for the x distance. but can be modified slightly to work in an x AND y situation.

dont use

- Player is in a range of + or -250 pixels (depending on the position of player relative to the enemy) from the enemy (X axis)
- Player is in a range of -10 to +10 pixels from the enemy (Y axis)

because that makes a square which doesnt accurately depict distance. the enemy could be +10 and 250 away which is farther than 0 and 250. its just not good practice.

use a distance formula to put the distance of the enemy from the player into an alterable.

distance^2 = x^2 + y^2

distance = sqrt(x^2 + y^2)

x would be the x distance between enemy and player, and y would be y distance between enemy and player. that formula gives you the distance in between based on their x's and y's.

simply compare the distance to a fixed value to check if its close enough.



Uh no, it works for Y as well. I'll upload the example when I get home. You just do the same exact thing for Y and add it in the same event. Yeah, it's only for a box though.

Image Edited by an Administrator.

 
Craps, I'm an old man!

Cecilectomy

noPE

Registered
  19/03/2005
Points
  305

Has Donated, Thank You!VIP MemberWeekly Picture Me This Winner!Cardboard BoxGhostbuster!Pokemon Ball!ComputerBox RedSanta HatSnowman
I am an April Fool
20th May, 2008 at 16:13:10 -

thats what i was meaning. you either do it for x or for y. not both in the same. thats how i used to do enemy zones and distance. its just not good, its horribly innacurate, unless youre really wanting a box zone area.

 
n/a

Knudde (Shab)

Administrator
Crazy?

Registered
  31/01/2003
Points
  5125

Has Donated, Thank You!Clickzine StaffKlikCast StarVIP MemberGhostbuster!Dos Rules!I donated an open source project
20th May, 2008 at 16:59:10 -

Well technically a box include both X and Y, but I get what you mean. Yeah, it whatever I used this for (pre Aru Core I think) it didn't matter if it was a box.

 
Craps, I'm an old man!

Cecilectomy

noPE

Registered
  19/03/2005
Points
  305

Has Donated, Thank You!VIP MemberWeekly Picture Me This Winner!Cardboard BoxGhostbuster!Pokemon Ball!ComputerBox RedSanta HatSnowman
I am an April Fool
20th May, 2008 at 22:19:13 -

que?

from where?

 
n/a

jbjovi



Registered
  22/07/2007
Points
  41
21st May, 2008 at 01:27:59 -

Ok, with the picture I understand what you mean now.

And you're right, the zone created by your method is more logical than mine. Except that I'm working on a platform game, and the square is good in that case (the enemy I'm working on precisely). But I'm curious to see a short exemple of your method cause I'm planning to have flying enemies, and in this case, your method will be better.

This subject would be a good subject for a tutorial I think...

EDIT : I asked an exemple because I don't know what mean ^ and sqrt in math... Sorry I'm 35 years old, school is far away from me !

Image Edited by the Author.

 
n/a
   

Post Reply



 



Advertisement

Worth A Click