"Instance_create_depth" bug/annoying thing

M

Mosaknows

Guest
Hey, Recently I've been working on my own boss A.I., but I've encountered an annoying problem.
Whenever I try to use the function "instance_create_depth" on my bot, on the first frame the instance that it creates spawns in the wrong coordinates which makes it look bad. I've tried many things to fix this, but no luck.

2 examples of some code
Code:
if (time >= 12 and time <= 13) && (cooldown < 1)
{
    instance_create_depth(x - 50 ,y,1,Obj_rocket)
    cooldown = 20;
}

if (time >= 16 and time <= 17) && (cooldown < 1)
{
    instance_create_depth(x + 50 ,y,1,Obj_rocket)
    cooldown = 20;
}

//Code by Mosaknows
GMS 2.1.5

and

Code:
if (x <= 960)
{
 s = instance_create_depth(x + 50 ,y,1,Obj_lazer);
 s.direction = 0;
 s.speed = spd;

 s = instance_create_depth(x + 50,y + 50,2,Obj_lazer);
 s.direction = 315;
 s.speed = spd;

 s = instance_create_depth(x,y + 50,3,Obj_lazer);
 s.direction = 270;
 s.speed = spd;

}

//Code by Mosaknows
GMS 2.1.5
 
Last edited by a moderator:
When you say it spawns at the wrong coordinates, what do you mean - where exactly on screen is it spawning compared with where you want it to be (somewhere close to the boss it appears from your code).

What code do you have in the Create Event of Obj_lazer and Obj_rocket? Is there anything there that changes the x and y values?

Also, I suggest using the debugger and set a break point just before you create the instances, then step through the code and check what is happening.
 
M

Mosaknows

Guest
When you say it spawns at the wrong coordinates, what do you mean - where exactly on screen is it spawning compared with where you want it to be (somewhere close to the boss it appears from your code).

What code do you have in the Create Event of Obj_lazer and Obj_rocket? Is there anything there that changes the x and y values?

Also, I suggest using the debugger and set a break point just before you create the instances, then step through the code and check what is happening.
I've figured out the issue, I needed to put "image_angle = directions" in a create event and not just the step event.
 
Top