Plz help me with my game...

Posted by n1ko on June 30, 2006, 6:26 p.m.

Yeah, im working on Hamlo. Its a platformer. i need help with one of the weapons. it needs to fire a projectile that (if it is close enough) moves towards an slightly follows its target,*coughs a noise that sounds similar to "just like the needler from Halo, only platform style"*. Any ways, i ve made it work pretty good, but the only problem is that it cannot choose between targets, it always goes after the same enemy, rather than the nearest one.

Basically, this is what the bullet obj does:

In the step event, it checks to see if there is a collision with objenemy within a rectangle.

If there isnt, it goes straight.

If there is, then it:

sets variable Facing_Direction to point_direction(x,y,enemy.x,enemy.y)

Then, it moves in direction : Facing Direction at speed 15.

Like i siad, it works fine if there is only one enmy, but if not, then it always seeks the original enmy. Can some one help me make the bullet determine if there is a closer enemy to follow? I use the latest gm, but i only have unreg. I also have VERY little coding exp., so please make any help simple! thnx!

EDIT: thanxs 64d! i got it to work! yay!

Comments

Tasm 17 years, 10 months ago

give all the enemy objects the same parent, then have the projectile follow the parent object.

n1ko 17 years, 10 months ago

no, i mean there are multiple instances of the same enemy, not multiple different enemys.

KaBob799 17 years, 10 months ago

same enemy is easy

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.

melee-master 17 years, 10 months ago

Or, do this:

var enemyNearest;
     enemyNearest = instance_nearest(x, y, enemy);
Facing_Direction = point_direction(x,y,enemyNearest.x,enemyNearest.y);

n1ko 17 years, 10 months ago

thanks guys! that helps me out a lot!8)

oh, and a admin or somone can take this blog off the front page if needed.