Q
qbot21
Guest
Hello!!!
I came across a problem that when I fire a gun, four instances of a bullet are created at once (each on top of other). I really don't have idea what causing this problem :/
I have a parent o_player obj, which have three childs. Each child inherits whole step event from the parent. At start of the level you can choose which and how many child obj's you want to have in room.
Parent step:
shooting script:
Any help or ideas are appreciated. Thank you!
I came across a problem that when I fire a gun, four instances of a bullet are created at once (each on top of other). I really don't have idea what causing this problem :/
I have a parent o_player obj, which have three childs. Each child inherits whole step event from the parent. At start of the level you can choose which and how many child obj's you want to have in room.
Parent step:
Code:
// Character avater
icon = char_class[class, 1];
spr = char_class[class, 2];
name = char_class[class, 3];
class_n = char_class[class, 4];
// Character base stats
hp_max = char_class[class, 5];
hp = hp_max;
spd = char_class[class, 6];
acc = char_class[class, 7];
crit = acc * .1;
// State on start of level
if state != player.spawn{
unit_select();
}
// Skill cooldown
id.skill_1_cd = clamp(id.skill_1_cd, 0, cd);
id.skill_2_cd = clamp(id.skill_2_cd, 0, cd);
if id.skill_1_cd > 0{
id.skill_1_cd -= 1;
}
if id.skill_1_cd == 0{
id.skill_1_ready = true;
}
switch (state) {
case player.spawn:
spr = s_char_2;
break;
case player.movement:
if id.active{
if mouse_check_button_pressed(mb_right){
var _xx = mouse_x;
var _yy = mouse_y;
if mp_grid_path(global.grid, my_path,x, y, _xx, _yy, true){
path_start(my_path, spd, path_action_stop, false);
}
}
if id.skill_1_ready{
if keyboard_check_pressed(ord("Q")){
path_end();
state = player.skill_1;
}
}
}
break;
case player.skill_1: // use skill 1
char_skills(id.skill_1); //shooting, argument taken from child obj!!!
state = player.movement;
break;
case player.skill_2:
break;
case player.downed:
break;
case player.dead:
break;
}
show_debug_message(instance_number(o_bullet));
Code:
skill = argument0;
switch (skill){
case 0:
var inst = instance_create_layer(x,y,"Instances",o_bullet);
with(inst){
motion_add(point_direction(x,y,mouse_x,mouse_y), 3);
}
id.skill_1_ready = false; // disable skill use
cd = 60; // cooldown value
id.skill_1_cd = cd; // set skill cooldown
break;
case 1:
show_message("Skill 2 used !!!");
cd = 90;
break;
}