GameMaker Direction of Bullets (point_direction)

S

supernova12034

Guest
Hi there,
I'm just getting started, I watched the tutorials and built my first little game, now i'm trying to take the next steps.

The tutorial has you create a little shooter game, and has you shooting enemy objects, the problem is that the code has you shooting essentially using your mouse to aim(wherever you point the mouse is where the bullets will fly), what I would like to do is just have the bullets come out of a one place(like the front of the player sprite) so instead of using the mouse to aim, I can just use the player object to aim and shoot.

Here is the code:

Code:
direction = point_direction(x,y,mouse_x,mouse_y);
// Bullet motion, to figure out direction of bullet fire.


direction = direction + random_range(-4,4)
//randomizes the position and dispersal of the
//bullets.

speed = 16; 

image_angle = direction;
This is coming from the bullet object, create event


Thank you, any help would be appreciated
 
P

Pyxus

Guest
Hi there,
I'm just getting started, I watched the tutorials and built my first little game, now i'm trying to take the next steps.

The tutorial has you create a little shooter game, and has you shooting enemy objects, the problem is that the code has you shooting essentially using your mouse to aim(wherever you point the mouse is where the bullets will fly), what I would like to do is just have the bullets come out of a one place(like the front of the player sprite) so instead of using the mouse to aim, I can just use the player object to aim and shoot.

Here is the code:

Code:
direction = point_direction(x,y,mouse_x,mouse_y);
// Bullet motion, to figure out direction of bullet fire.


direction = direction + random_range(-4,4)
//randomizes the position and dispersal of the
//bullets.

speed = 16;

image_angle = direction;
This is coming from the bullet object, create event


Thank you, any help would be appreciated
Seems the bullets are moving due to the instance's built in speed variable, and the speed variable is governed by the direction. To shoot straight forwards, all you have to do is change your direction. Setting direction to equal 90 should cause the bullet to just shoot straight up.
 
S

supernova12034

Guest
That seems to have sort of worked, however I should have been more clear, I would like to shoot straight in the direction the player object is facing, so if the object is facing left, shoot left, if the object is facing right, shoot right

So on and so forth. Setting direction equal to just 90 causes it to just shoot upwards, regardless of where I point the player object
 
M

Mahdarah

Guest
That seems to have sort of worked, however I should have been more clear, I would like to shoot straight in the direction the player object is facing, so if the object is facing left, shoot left, if the object is facing right, shoot right

So on and so forth. Setting direction equal to just 90 causes it to just shoot upwards, regardless of where I point the player object
Try setting the bullet's direction to the player's direction on its create event
 
R

Ragedleinad

Guest
Basicly when you go left shoot left, and when you go right shoot right? Please check the attachment I uploaded, I did a litte code to test it out, is it this what you want?

Player object

Code:
//Movement
if keyboard_check(ord("A"))
   {
   x -=8;
   direction=180;
 
   }
if keyboard_check(ord("D"))
   {
   x +=8;
   direction=0;
   }
//Shooting with mouse
 if(mouse_check_button(mb_left)){
    newBullet=instance_create_layer(x,y,"Bullet",oBullet);
    newBullet.direction=oPlayer.direction;
    newBullet.speed=9;
  
}
This basicly shoots in the directtion the player is facing and really depends on what type of game you want

Hope this helps
 

Attachments

Basicly when you go left shoot left, and when you go right shoot right? Please check the attachment I uploaded, I did a litte code to test it out, is it this what you want?

Player object

Code:
//Movement
if keyboard_check(ord("A"))
   {
   x -=8;
   direction=180;

   }
if keyboard_check(ord("D"))
   {
   x +=8;
   direction=0;
   }
//Shooting with mouse
if(mouse_check_button(mb_left)){
    newBullet=instance_create_layer(x,y,"Bullet",oBullet);
    newBullet.direction=oPlayer.direction;
    newBullet.speed=9;
 
}
This basicly shoots in the directtion the player is facing and really depends on what type of game you want

Hope this helps
Yo I've been trying to figure out how to change my direction, I've been trying so many complicated things and this is what worked. Thanks +1
 
Top