• Hey Guest! Ever feel like entering a Game Jam, but the time limit is always too much pressure? We get it... You lead a hectic life and dedicating 3 whole days to make a game just doesn't work for you! So, why not enter the GMC SLOW JAM? Take your time! Kick back and make your game over 4 months! Interested? Then just click here!

GML Visual How do I make generated bullet leave tip of gun as the gun rotates?

G

guitarmonkeys14

Guest
Hey all, I am currently making a top/down 2D shooter and I am running into an issue.

I cannot make the spawn point of the bullet rotate with my character. I tried adjusting the X and Y of the "Jump To Point" in the bullets Create Event and got it to shoot out of the tip of the gun, but when I rotate my character it stays spawning at that same point. How do I set the bullet to spawn based off of a set point of the players sprite (i.e. the tip of the gun) regardless of player angle?

Code:
// Jump To Point
x += (image_angle +20);
y += (image_angle -95);

// Set Instance Rotation
image_angle += point_direction(x,y,mouse_x,mouse_y);

// Set Speed
speed += 6;
upload_2019-1-21_15-42-52.pngupload_2019-1-21_15-43-22.png

Alternatively I was wondering if there was something I could insert where I created the bullet after the "instance_create_layer("

Code:
// If Mouse Down
var l0248E0E1_0;
l0248E0E1_0 = mouse_check_button(mb_left);
if (l0248E0E1_0)
{
   // Create Instance
   newbullet = instance_create_layer(x + 0, y + 0, "Instances", obj_bullet);

   // Assign Variable
   newbullet.direction += image_angle;
}
Been stuck on this all day :/
Please help
 
Last edited by a moderator:

Khao

Member
Code:
// Assign Variable
newbullet.direction += image_angle;
You basically got this backwards, you're basically telling the bullet to modify its current direction by the value of the its current angle (which is always 0 in this scenario, so nothing will happen), but you need to

Instead of setting newbullet.direction equal to image_angle, set newbullet.image_angle to newbullet.direction (or newbullet.image angle to simply image_angle, if that doesn't work). And in this case, uncheck "relative", because the angle should be absolute.

EDIT:

Scratch that, I had a bit of a misinterpratation.

Don't replace anything. Just add a new line setting newbullet.image_angle to newbullet.direction. Not relative.
 
G

guitarmonkeys14

Guest
Code:
// Assign Variable
newbullet.direction += image_angle;
You basically got this backwards, you're basically telling the bullet to modify its current direction by the value of the its current angle (which is always 0 in this scenario, so nothing will happen), but you need to

Instead of setting newbullet.direction equal to image_angle, set newbullet.image_angle to newbullet.direction (or newbullet.image angle to simply image_angle, if that doesn't work). And in this case, uncheck "relative", because the angle should be absolute.

EDIT:

Scratch that, I had a bit of a misinterpratation.

Don't replace anything. Just add a new line setting newbullet.image_angle to newbullet.direction. Not relative.
Thank you thank you!

Do you have any suggestions for the other issue?

I am still unable to make the bullet always spawn from the tip of the gun... I thought it would work to use xstart and ystart but they don't seem to be working... I feel like I am missing something or not setting it up correctly

Code:
// If Mouse Down
var l0248E0E1_0;
l0248E0E1_0 = mouse_check_button(mb_left);
if (l0248E0E1_0)
{
   // Create Instance
   newbullet = instance_create_layer(x + 0, y + 0, "Instances", obj_bullet);

   // Assign Variable
   newbullet.direction += image_angle;

   // Assign Variable
   newbullet.xstart += 100;
}
upload_2019-1-21_14-39-4.png

Any suggestions?
 
Top