M
Mark M
Guest
Hi everyone,
I've recently started using GameMaker Studio 2. I'm playing around with a basic 2D platformer to get used to GML etc... But I've run into a problem when combining keyboard/mouse checks and collision detection.
On startup, the bullets shoot correctly when the mouse is pressed. If I hold the mouse key I can also move and jump etc. The problem is when I move/jump before clicking the mouse button. The bullet does not appear to be created and it takes several frames before the mouse click is registered again.
The movement and collision detection is all taken from the platform tutorial. I've simply tried to add a mouse_check to create a new instance.
I'm probably missing something obvious but a fresh pair of eyes might help. I can't see why it's not working!
Player "Create" Event:
Player "Step" Event:
Here is the bullet create event also, although I do not believe it is the cause of the problem:
Any help with this would be greatly appreciated
I've recently started using GameMaker Studio 2. I'm playing around with a basic 2D platformer to get used to GML etc... But I've run into a problem when combining keyboard/mouse checks and collision detection.
On startup, the bullets shoot correctly when the mouse is pressed. If I hold the mouse key I can also move and jump etc. The problem is when I move/jump before clicking the mouse button. The bullet does not appear to be created and it takes several frames before the mouse click is registered again.
The movement and collision detection is all taken from the platform tutorial. I've simply tried to add a mouse_check to create a new instance.
I'm probably missing something obvious but a fresh pair of eyes might help. I can't see why it's not working!
Player "Create" Event:
Code:
player_speed = 4;
player_jump_power = 9;
base_gravity = 0.2;
horiz_spd = 0;
vert_spd = 0;
shot_cooldown = 0;
Code:
mouse_left = mouse_check_button(mb_left);
key_right = keyboard_check(ord("D"));
key_left = -keyboard_check(ord("A"));
key_up = keyboard_check_pressed(ord("W"));
//fire check
if(mouse_left){
instance_create_layer(x,y,"bullet_layer",obj_bullet);
}
//movement
move = key_right + key_left;
horiz_spd = move * player_speed;
if(vert_spd < 10){
vert_spd += base_gravity;
}
if (place_meeting(x,y+1,obj)){
vert_spd = key_up * -player_jump_power;
}
//collision checks
if(place_meeting(x+horiz_spd,y,obj_terrain)){
while(!place_meeting(x+sign(horiz_spd),y,obj_terrain)){
x += sign(horiz_spd);
}
horiz_spd =0;
}
if(place_meeting(x,y+vert_spd,obj_terrain)){
while(!place_meeting(x,y+sign(vert_spd),obj_terrain)){
y += sign(vert_spd);
}
vert_spd =0;
}
x += horiz_spd;
y += vert_spd;
Code:
direction = point_direction(x,y,mouse_x,mouse_y);
direction = direction + random_range(-3,3);
speed = 15;
image_angle = direction;