Jump to content


Photo

Return the id,


  • Please log in to reply
4 replies to this topic

#1 Andy

Andy

    GMC Veteran

  • GMC Member
  • 1819 posts
  • Version:GM:Studio

Posted 05 June 2011 - 11:52 PM

I have:
- Enemy objects.
- Good guy objects.
- Wall objects.
I need to figure out how to return the id, (from the enemy object,) of the nearest good guy who isn’t blocked by a wall. I then need to make that id into a variable.
I already know how, to do the collision checking to see if the good guy is in view, I just need to return the id of the nearest good guy "in sight." (So to speak.)

All help is greatly appreciated, that you for your time.


  • 0

#2 LedgendaryHero

LedgendaryHero

    GMC Member

  • New Member
  • 648 posts

Posted 06 June 2011 - 12:28 AM

what sucks about doing something like this is you have to check for every instance of that object type :/
let's say it's name obj_good, and you're obj_player:
global.dist=999999//will carry how far away nearest is, for comparing
global.obj=-1 //will carry id of closest object
with (obj_good)//all obj_goods will do this
{
if collision_line(x,y,obj_player.x,obj_player.y,obj_wall,false,true)
if point_distance(x,y,obj_player.x,obj_player.y)<global.dist //if its closer than the closest
{
global.dist=point_distance(x,y,obj_player.x,obj_player.y)
global.obj=id
}
}
//global.obj will have the id of the nearest obj_good who isnt blocked

:/ it sucks because, depending on how many there are, you could be calling this a LOT (once for every obj_good), but it seems necessary.

Edited by LedgendaryHero, 06 June 2011 - 12:30 AM.

  • 0

#3 Andy

Andy

    GMC Veteran

  • GMC Member
  • 1819 posts
  • Version:GM:Studio

Posted 06 June 2011 - 02:26 AM

The thing is there are multiple allies/enemies.
There could be (up to) 20 "good guys" fighting (up to) 20 "bad guys" in any given room. Twenty, for each side, is the limit. I limit the number for performance. To many thinking objects tend to slow down everything. Here are the arrays that cover the field of vision blockers, allies, and foes.

global.fov_block[i]
global.ally[i]
global.foe[i]
  • 0

#4 LedgendaryHero

LedgendaryHero

    GMC Member

  • New Member
  • 648 posts

Posted 06 June 2011 - 02:38 AM

Do you understand the concept of parent's?
make a parent object for all 'allies'. make one for all 'enemies'. the with(object) handles it by having every instance of object type object execute the following code. In other words, if you have twenty instances of obj_ball, and the code
with (obj_ball)
score+=1
your score would be increased by twenty; all the balls did the code.
I feel as if i'm not understanding. If this didn't answer your question, can you clarify? I'm confused what you mean 20 "good guys"
  • 0

#5 mrpeanut188

mrpeanut188

    GMC Member

  • GMC Member
  • 811 posts
  • Version:GM8

Posted 06 June 2011 - 02:51 AM

Do you understand the concept of parents?


The others will inherit the events and behave exactly the same way.

Just incase....

...of the nearest good guy...

enemy = instance_nearest(x,y,PARENTOFGOODPEOPLE)

...who isn’t blocked by a wall...

collision_line(x,y,enemy.x,enemy.y,WALLOBJECT,0,1)

But, thinking in computer terms, combining would be a bit of a pain....
I would do it, but I GTG...
  • 0




0 user(s) are reading this topic

0 members, 0 guests, 0 anonymous users