Jump to content


Photo

Lock on an enemy


  • Please log in to reply
8 replies to this topic

#1 Bladestorm Games

Bladestorm Games

    GMC Member

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

Posted 25 April 2012 - 02:46 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 1597532846

1597532846

    BANNED

  • GMC Member
  • 233 posts
  • Version:Unknown

Posted 25 April 2012 - 02:50 AM

--Deleting Online Presence--


Edited by The2Banned2One, 14 October 2014 - 12:40 AM.

  • 1

#3 Bladestorm Games

Bladestorm Games

    GMC Member

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

Posted 25 April 2012 - 05:11 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

#4 1597532846

1597532846

    BANNED

  • GMC Member
  • 233 posts
  • Version:Unknown

Posted 26 April 2012 - 03:33 AM

--Deleting Online Presence--


Edited by The2Banned2One, 14 October 2014 - 12:37 AM.

  • 0

#5 Bladestorm Games

Bladestorm Games

    GMC Member

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

Posted 26 April 2012 - 04:38 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:39 AM.

  • 0

#6 1597532846

1597532846

    BANNED

  • GMC Member
  • 233 posts
  • Version:Unknown

Posted 26 April 2012 - 04:44 AM

--Deleting Online Presence--


Edited by The2Banned2One, 14 October 2014 - 12:37 AM.

  • 0

#7 Bladestorm Games

Bladestorm Games

    GMC Member

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

Posted 26 April 2012 - 05:01 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

#8 1597532846

1597532846

    BANNED

  • GMC Member
  • 233 posts
  • Version:Unknown

Posted 26 April 2012 - 10:51 AM

--Deleting Online Presence--


Edited by The2Banned2One, 14 October 2014 - 12:37 AM.

  • 0

#9 1597532846

1597532846

    BANNED

  • GMC Member
  • 233 posts
  • Version:Unknown

Posted 26 April 2012 - 10:44 PM

--Deleting Online Presence--


Edited by The2Banned2One, 14 October 2014 - 12:37 AM.

  • 0




0 user(s) are reading this topic

0 members, 0 guests, 0 anonymous users