Help - Search - Members - Calendar
Full Version: Multiple Instances Of The Same Object
Game Maker Community > Working with Game Maker > Advanced Users Only
onza40
Hey, I'm working on a game at the moment in which you construct towers and then these towers fire upon incoming enemies. All the enemies are obj_ball. I have a script which finds the distance between obj_tower and obj_ball and if it's below a variable "range" the tower fires an obj_bullet, and as game maker automatically deals with the first obj_ball created the distance measured to and the ball the bullet targets are always the first obj_ball.
Now the bit I need help with.
I want the tower to fire at whichever obj_ball is closest to it not just the first one. This means that even when the first ball is out of range the tower still does something.
Please help someone, I want this game finished quite soon.
Thanks to anyone who helps.
Alex (Onza40)
Gumgo
QUOTE
instance_nearest(x,y,obj) Returns the id of the instance of type obj nearest to (x,y). obj can be an object or the keyword all.
tikiblue
to find out which is the nearest obj_ball use
CODE
enemy = instance_nearest(x,y,obj_ball)

put this in the step action for the tower and let the tower treat all obj_ball as enemy
if that was the question laugh.gif
onza40
Sweet, thanks guys, this may appear in WIPs quite soon because of ur help.
This is a "lo-fi" version of our main content. To view the full version with more information, formatting and images, please click here.
Invision Power Board © 2001-2010 Invision Power Services, Inc.