• 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!

(SOLVED)How can I make a bullet appear from the end of a gun when the gun can change angle??

D

Den

Guest
I have a system set up where you aim with the mouse but I can't figure out how to make the bullet spawn from
what ever angle my gun is at. I need a way to some how check the angle the gun is so I can update the x and y potions for the bullet creation.
 

nesrocks

Member
when you create the bullet
var mybullet = instance_create(obj_gun.x,obj_gun.y, obj_bullet)
with mybullet direction = obj_gun.direction;
 
D

Den

Guest
when you create the bullet
var mybullet = instance_create(obj_gun.x,obj_gun.y, obj_bullet)
with mybullet direction = obj_gun.direction;
That doesn't work is just comes out straight not at the angle the gun is pointing.
The part that moves is an arm holding a gun too, if that helps.
 
?

!!!!!

Guest
Showing your code always helps, and screenshots. If you're rotating obj_gun with image_angle, you could get the direction from that.

var mybullet = instance_create(obj_gun.x,obj_gun.y, obj_bullet)
with mybullet direction = obj_gun.image_angle

Else you could use the same code for finding the gun direction for the bullet direction.
Most likely the bullet is being created inside the arm too instead of where the gun is!
 
D

Den

Guest
Showing your code always helps, and screenshots. If you're rotating obj_gun with image_angle, you could get the direction from that.

var mybullet = instance_create(obj_gun.x,obj_gun.y, obj_bullet)
with mybullet direction = obj_gun.image_angle

Else you could use the same code for finding the gun direction for the bullet direction.
Most likely the bullet is being created inside the arm too instead of where the gun is!
I am using image angle, so how would I do that? direction = Shooting_arm.image_angle right?
The arm code:
Code:
///Initiate The Shooting Arm
var attack = mouse_check_button_pressed(mb_left);
image_angle = point_direction(x,y,mouse_x,mouse_y);

x = obj_player.x +8;
y = obj_player.y -9;

//move arm to the left
if(obj_player.image_xscale == -1) {
  x-= 16;
}


 if (mouse_x <= (obj_player.x + 7)) { //<<Move with the player
    image_yscale = -1;
  }
  else {
    image_yscale = 1;
  }
 
D

Den

Guest
Also, use the built in variable speed to move the bullet. That way it will follow the direction.
Showing your code always helps
Manged to figure it out guys using length_dir:
Code:
 bullet = instance_create(x+ lengthdir_x(15,image_angle), y+ lengthdir_y(15,image_angle),obj_bullet)
I just got the distance from the arms origin to the end of the gun.
Thanks for the help tho :)
 
Top