Why are my bullets flying in weird directions?

旧城冷巷雨未停 提交于 2020-02-07 00:01:10

问题


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

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!