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

Trying to rotate bullets with the player

M

Mr_koozit

Guest
Im trying to make my character shoot in a straight line but i cant
make make the bullets rotate when the player is rotating too:
---------------------------------------------------------------------------------------------------------------------------------------------------
firingdelay = 0
---------------------------------------------------------------------------------------------------------------------------------------------------
x = player.x+5;
y = player.y+46;
firingdelay = firingdelay -1;
if (mouse_check_button(mb_left)) && (firingdelay < 0)
{
firingdelay = 5;
with (instance_create_layer(x,y,"Bullets",bullet))
{
speed = 25;
direction = other.image_angle;
image_angle = direction;
}
}
 

Attachments

B

Bořek Tuleja

Guest
Are you even changing the value of image_angle in the player? Because by default it's set to 0 - right. You should set bullet's direction to player's direction and not image_angle.
Code:
speed = 25;
direction = other.direction;
image_angle = direction;
 
M

Mr_koozit

Guest
Are you even changing the value of image_angle in the player? Because by default it's set to 0 - right. You should set bullet's direction to player's direction and not image_angle.
Code:
speed = 25;
direction = other.direction;
image_angle = direction;
I did this and it still dosent work:
if keyboard_check(vk_left) && (keyboard_check(ord("A")))
{
direction = 1
}
else
{
direction = 0
}
 
B

Bořek Tuleja

Guest
I did this and it still dosent work:
if keyboard_check(vk_left) && (keyboard_check(ord("A")))
{
direction = 1
}
else
{
direction = 0
}
This is not how you change direction. Direction is in degrees. That means: 0° - right, 90°- up, 180° - left, 270° - down. You need to change it like this:
Code:
if (keyboard_check(vk_left)) {
    direction = 180;
}

if (keyboard_check(vk_right)) {
    direction = 0;
}
 
M

Mr_koozit

Guest
This is not how you change direction. Direction is in degrees. That means: 0° - right, 90°- up, 180° - left, 270° - down. You need to change it like this:
Code:
if (keyboard_check(vk_left)) {
    direction = 180;
}

if (keyboard_check(vk_right)) {
    direction = 0;
}
It works but the bullets change direction only if i press the D/A buttons so it goes like that:
---------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
- The player is set to face right by default
- The player shoots and the bullets go right because he is facing to the right
- If i press the "D" button to face left the bullets will shift direction in mid-air to the left and fly left only for the time i press the button
---------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
I want the bullets to not change a direction in mid-air and fly right or left according to the player direction
 
Top