Legacy GM shooting code help

D

darakin

Guest
hello can somebody help me please I am having trouble with my code its only supposed to shoot one bullet but it shoots 3 and in only one direction im making a platformer btw


heres my code


//create bullet
{
b = instance_create(x,y,obj_bullet);
bullets -= 1;
b.speed = 15


//check direction

if (image_xscale = 1) {
b.direction = 0;
} else {
b.direction = 180; }
}
 

obscene

Member
That code creates 1 bullet, not 3, so you have outside circumstances that are the problem here you haven't posted.
 

Fabseven

Member
Did you use the évent touch released or touch pressed ? I think the second one trigger multiple Times if you keep the touch pressed....
 
K

Karlabos

Guest
Cannot tell what's happening by this piece of code...
For the direction problem, what exactly triggers whether the image_xscale of the object is set to 1 or else?
As for the mutiple shooting instead of just 1, is this code on which event and/or inside which "if" conditions?
It would help to post more of the related codes
 
D

darakin

Guest
im sorry I haven't replied I have been busy and I apologize for not posting more of the code here is more...





this is in the step event of obj_player


{
//moving left and right
if (keyboard_check(vk_right) && place_free(x+4,y) && !keyboard_check(vk_left)) {
if (place_free(x,y+1)) {
if(place_free(x+4,y+vspeed)) {
x+=4;
}
} else {
x+=4;
}
} else if (keyboard_check(vk_left) && place_free(x-4,y)&& !keyboard_check(vk_right)) {
if (place_free(x,y+1)) {
if(place_free(x-4,y+vspeed)) {
x-=4;
}
} else {
x-=4;
}
}


//gravity
if (place_free(x,y+1)) {
gravity = .75;

// set max fall speed
if(vspeed >=10) {
vspeed = 10;
}







this is in the key press event of obj_player_shoot


{
image_speed = .5;
instance_change(obj_player_shoot,false);
}


} else {
gravity = 0;

//jumping
if (keyboard_check_pressed(vk_up)) {
vspeed = -10;
}
}
}






and this is in the step event of obj_player_shoot




//create bullet
{
b = instance_create(x,y,obj_bullet);
bullets -= 1;
b.speed = 15


//check direction

if (image_xscale = 1) {
b.direction = 0;
} else {
b.direction = 180; }
}
 

Fabseven

Member
Hello,
I do not understand why you have an obj_player and an obj_player_shoot.
Another thing i donot understand : why you create your bullet in the step event of obj_player_shoot with no condition...

If it was me i would
Create an objet obj_player like you did

STEP EVENT = code for moving / jumping
SPACE RELEASED EVENT : create a obj_bullet.
 
D

darakin

Guest
Hello,
I do not understand why you have an obj_player and an obj_player_shoot.
Another thing i donot understand : why you create your bullet in the step event of obj_player_shoot with no condition...

If it was me i would
Create an objet obj_player like you did

STEP EVENT = code for moving / jumping
SPACE RELEASED EVENT : create a obj_bullet.

From what I understand from the video tutorial I was watching the shoot object is the shoot animation and the player object turns into the shoot object when triggered to via the shoot button so it makes it where when I shoot it triggers the shoot animation and looks like my sprite is shooting but if there's a better way I'm all ears I was just following the video
 

Fabseven

Member
First try to just shoot something.
SO forget about the obj_player_shooting,
If you want to test create an obj_player_2
STEP event : paste your code to move
SPACE RELEASED event :

Code:
u = instance_create(x,y,obj_bullet)
u.direction = point_direction(x,y, mouse_x,mouse_y)
u.image_angle = u.direction
u.speed = 5
This code should shoot a bullet at mouse direction from the player's center.
That's the first step.
After this you could use an alarm or a timer to make a cooldown.
You could also not shoot with space but with the right click.

Tell us if you could do this.
 
Top