问题
I've been making a twin-stick shooter with GML for a while, and I've gotten to the point where I want the ship to shoot bullets. I wrote the code below, with the intention of making the fire fire at wherever the cursor is, but for some reason the bullets fire in strange directions. One time it will be shooting in the right direction, at other times it will be towards an angle, other times behind the ship. The only clue I have is that for some reason it's not genuinely random, it only seems to change whenever I move the cursor or the ship. Can someone please check my code?
image_angle = point_direction(x,y,mouse_x,mouse_y);
if (mouse_check_button(mb_left) && Reload < 0)
{
angle = point_direction(x,y,mouse_x,mouse_y);
Reload = 20;
with (instance_create_layer(x+cos(angle)*50, y+sin(angle)*50, "Bullets", Bullet))
{
angle = other.angle;
dx = cos(angle);
dy = sin(angle);
image_angle = angle;
}
}
else {Reload = clamp(Reload-1, -10, 20)}
来源:https://stackoverflow.com/questions/59385400/why-are-my-bullets-flying-in-weird-directions