F
Freedom2Fight
Guest
Hello, again. I would like to request your help.
I am making a platformer. I am relatively new to this and I am very eager to learn.
So here is the situation:
I want the playable character to able to shoot projectiles in the direction they are facing.
Whenever I press the [Attack Button] the character will [shoot] and a [bullet will launch] in the [direction they are facing]. Please see illustration below.
It also doubles as a rorschach test
The code I provided below allows the player shoot. However there is a problem, please see illustration below:
There are also a number of issues I have yet to deal with such as the bullet destroying itself upon collision with walls and enemies. Right now, I just want the bullet to travel to the correct direction.
Here is the code:
Attack is a variable I set up as False in the Create Event.
Attack = keyboard_check_pressed(ord"Z"))
The code above seem to only let the projectile travel to the right, if the bullet is facing left it still travels to the right.
I am fairly certain that the speed, direction of the bullet and the bullet itself should be generated through the player. Although, I am not entirely sure how to go about it.
How would one go about executing this?
As always, looking forward to your responses.
I am making a platformer. I am relatively new to this and I am very eager to learn.
So here is the situation:
I want the playable character to able to shoot projectiles in the direction they are facing.
Whenever I press the [Attack Button] the character will [shoot] and a [bullet will launch] in the [direction they are facing]. Please see illustration below.
It also doubles as a rorschach test
The code I provided below allows the player shoot. However there is a problem, please see illustration below:
There are also a number of issues I have yet to deal with such as the bullet destroying itself upon collision with walls and enemies. Right now, I just want the bullet to travel to the correct direction.
Here is the code:
Attack is a variable I set up as False in the Create Event.
Attack = keyboard_check_pressed(ord"Z"))
Code:
if Attack
{
sprite_index = spr_rangedattack;
if sprite_index = spr_rangedattack
{
with(instance_create(x,y,obj_bullet))
{
image_xscale = other.image_xscale;
obj_bullet.speed = 15
with(instance_place(x,y,obj_enemy))
//Below checks if it is hitting an enemy
{
if(hit==0)
{
hit = 1;
vsp = -3;
hsp = sign(x - other.x)*4;
image_xscale = sign(hsp)
}
}
}
}
}
I am fairly certain that the speed, direction of the bullet and the bullet itself should be generated through the player. Although, I am not entirely sure how to go about it.
How would one go about executing this?
As always, looking forward to your responses.