A
AGameMaker
Guest
I'm trying to get a fully functioning turret to tell when my obj_Xwing is in range to rotate towards it and begin firing upon it. I got my code here and I've been piece it together from other sources i have found.
bulletSpeed = 4
//Find the nearest enemy:
nearest_enemy = instance_nearest(x,y,obj_Xwing);
//Make sure we actually have something to aim at!
if (nearest_enemy > 0) { //This is a GM pointer trick - pointers to objects are set to -1 if they're not pointing at anything
//Check to see how close that enemy is:
if (point_distance(x, y, nearest_enemy.x, nearest_enemy.y) < 200) {
//Spawn a bullet:
obj_TurretBullets = instance_create_depth(x,y, 5, obj_TurretBullets);
//Aim it at the specific enemy from earlier:
with (obj_TurretBullets) {
move_towards_point(other.nearest_enemy.x, other.nearest_enemy.y, bulletSpeed);
image_angle = direction;
}
}
}
//Aim it at the specific enemy from earlier:
obj_Xwing = nearest_enemy;
with (obj_TurretBullets) {
move_towards_point(x, y, obj_TurretBullets);
image_angle = direction;
}
it says it Cannot set a constant ("obj_TurretsBullets") to a value
also Cannot set a constant ("obj_Xwing") to a value
bulletSpeed = 4
//Find the nearest enemy:
nearest_enemy = instance_nearest(x,y,obj_Xwing);
//Make sure we actually have something to aim at!
if (nearest_enemy > 0) { //This is a GM pointer trick - pointers to objects are set to -1 if they're not pointing at anything
//Check to see how close that enemy is:
if (point_distance(x, y, nearest_enemy.x, nearest_enemy.y) < 200) {
//Spawn a bullet:
obj_TurretBullets = instance_create_depth(x,y, 5, obj_TurretBullets);
//Aim it at the specific enemy from earlier:
with (obj_TurretBullets) {
move_towards_point(other.nearest_enemy.x, other.nearest_enemy.y, bulletSpeed);
image_angle = direction;
}
}
}
//Aim it at the specific enemy from earlier:
obj_Xwing = nearest_enemy;
with (obj_TurretBullets) {
move_towards_point(x, y, obj_TurretBullets);
image_angle = direction;
}
it says it Cannot set a constant ("obj_TurretsBullets") to a value
also Cannot set a constant ("obj_Xwing") to a value