Lock on an enemy
#1
Posted 25 April 2012 - 02:46 AM
I hope this is enough details heh, thanks
#2
Posted 25 April 2012 - 02:50 AM
target = instance_nearest(x,y,objEnemyParent);
And then in the step event have it move towards target.
#3
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?
#4
Posted 26 April 2012 - 03:33 AM
/* Code Originally by Davve, Modified by The2Banned2One */
var ins, _id;
_id = -1;
while (1)
{
ins = instance_nearest(argument0,argument1,objEnemyParent)
if (ins > 0)
{
if (ins.lockedOn = false)
{
_id = ins;
break;
}
else
{
instance_deactivate_object(ins);
}
}
else
{
break;
}
}
instance_activate_object(object0);
return _id;
Then add the following to your objEnemyParent's create event:
lockedOn = false;
Then change the create event of your objHoverMine from:
target = instance_nearest(x,y,objEnemyParent);To:
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
Try that out and tell me if it works.
Edited by The2Banned2One, 26 April 2012 - 03:37 AM.
#5
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.
#6
Posted 26 April 2012 - 04:44 AM
Then add the following to your objEnemyParent's create event:
lockedOn = false;
I think you forgot this part.
#7
Posted 26 April 2012 - 05:01 AM
No it's in there. Isnt the error in the script?
Then add the following to your objEnemyParent's create event:lockedOn = false;
I think you forgot this part.
#8
Posted 26 April 2012 - 10:51 AM
Edited by The2Banned2One, 26 April 2012 - 10:51 AM.
#9
Posted 26 April 2012 - 10:44 PM
Just PM me your GMK and I'll see what I can do.
0 user(s) are reading this topic
0 members, 0 guests, 0 anonymous users











