My code to make the enemy shhot at the player isn't working

P

Paulo Henrique

Guest
i'm using this code:
Create Event:
alarm[0]= room_speed*5; // atira a cada 5 segundos
alarm Event:
var bullet = instance_create_layer(x, y,"Instances", obj_tiraoenemy); //cria e grava o ID das balas
with (bullet)
{
direction= point_direction(x,y,obj_player.x,obj_player.y); // da a direção da bala
speed=6;
}
alarm[0]= room_speed*5; // reseta os tiros

But the spacesships isn't makes the bullets. somebody help me
 
D

DarthTenebris

Guest
Try this instead:
Code:
Create:
alarm[0] = room_speed * 5;

Alarm 0:
with(instance_create_layer(x, y, "Instances", obj_tiraoenemy) {
     motion_set(point_direction(x, y, obj_player.x, obj_player.y), 6);
}
Make sure both the player and the bullet object exists in the resource editor and make sure the player exists in the room otherwise it will crash.
motion_set(direction, speed);

Hope I helped :)
 
Top