Jump to content


Photo

Lock on an enemy


  • Please log in to reply
3 replies to this topic

#1 Bladestorm Games

Bladestorm Games

    GMC Member

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

Posted 25 April 2012 - 03:00 AM

Pretty much what the tittle and description says, how can i make say; objHoverMine , find the neasrest objEnemyParent ,then THAT one it will follow even if another is near by as it travels toward the locked on enemy.

I hope this is enough details heh, thanks
  • 0

#2 Bladestorm Games

Bladestorm Games

    GMC Member

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

Posted 25 April 2012 - 05:25 PM

Make it so that in the create event:

target = instance_nearest(x,y,objEnemyParent);

And then in the step event have it move towards target.


Alright it works, but now I spawn (throw out) 3 objHoverMine , how can i make the 3 choose different objEnemyParent if there are more than 2 or 3 enemies?
  • 0

#3 Bladestorm Games

Bladestorm Games

    GMC Member

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

Posted 26 April 2012 - 04:52 AM

___________________________________________
ERROR in
action number 1
of Create Event
for object objHoverMine:

In script findNearestEnemy:
Error in code at line 10:
if (ins.lockedOn = false)
^
at position 16: Unknown variable lockedOn


Also i have the look on occur at the animation end of the objHoverMine:

if sprite_index = sprHoverMine
    then
    {   
        target = findNearestEnemy(x,y);

        if (target != -1) target.lockedOn = true;
        else instance_destroy(); //Destroy it because it couldn't find an enemy to lock onto

        stage_1 = true // stage 1 is complete and does stuff in step event
        sprite_index = sprHoverMineActive // now the mine is active and will hunt down the eneimies
    }


Step event
if speed <= 0 and stage_1 = false
    {
        speed -=0.1
    }

if stage_1 = true and instance_exists(target) and distance_to_object(target) <=200
    {
        if stage_1_speed <= 6
            {
                stage_1_speed += 0.3
            }
        move_towards_point(target.x,target.y,stage_1_speed)
    }
    
if stage_1 = true and !instance_exists(target)
    then
    {
        instance_create(x,y,objTestExplosion1)
        instance_destroy()
    }

Edited by Faultekaiser, 26 April 2012 - 04:53 AM.

  • 0

#4 Bladestorm Games

Bladestorm Games

    GMC Member

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

Posted 26 April 2012 - 05:15 AM

Then add the following to your objEnemyParent's create event:

lockedOn = false;


I think you forgot this part.

No it's in there. Isnt the error in the script?
  • 0




0 user(s) are reading this topic

0 members, 0 guests, 0 anonymous users