GMS 2 Double collision problem (sorry for the English)

AndreFS

Member
I have the following problem:

In my game, I have two weapons, when the player is over one of the two and right clicks, he takes that weapon, but if he is over two weapons, he takes one, and the other disappears
 

AndreFS

Member
Seeing some code would help. And your english is fine
on the weapon obj
collision event:
GML:
if obj_weapon.weapons[obj_weapon.weapon] == 0 and mouse_check_button_pressed(mb_right) and action_drop = 0 {
    alarm[0] = 1;
}

//in the alarm he changes the gun in his hand to the one on the floor
when the weapon is on the ground, it is an object, when the person picks up, it is another, so obj_weapon.weapons [obj_weapon.weapon] is an array that says all the parameters of the weapon being held.

alarm[0] :
GML:
with(obj_weapon){  
    ChangeWeapon(other.weapon);
    ammo[weapon] = other.ammo;
    max_ammo[weapon] = other.max_ammo;
    reload[weapon]  = other.reload;
}
instance_destroy();
 
Last edited:

Yal

šŸ§ *penguin noises*
GMC Elder
when the player is over one of the two and right clicks, he takes that weapon, but if he is over two weapons, he takes one, and the other disappears
What actually happens is: the player picks up BOTH, and whatever is picked up second overwrites the other.

There's a bunch of ways you can fix this:
  • After clicking once, set a cooldown (use a global variable canchangeweapons which is set to true in the create event, set to false when picking a weapon up, and then set back to true using e.g. an alarm which is set each time you pick up a weapon) so that the player can't pick up a weapon again too quickly.
  • Before picking up a weapon, drop the current weapon on the ground.
  • Pick up both and store them in array instead of overwriting the current weapon, and let the player change between them at will.
 

AndreFS

Member
What actually happens is: the player picks up BOTH, and whatever is picked up second overwrites the other.

There's a bunch of ways you can fix this:
  • After clicking once, set a cooldown (use a global variable canchangeweapons which is set to true in the create event, set to false when picking a weapon up, and then set back to true using e.g. an alarm which is set each time you pick up a weapon) so that the player can't pick up a weapon again too quickly.
  • Before picking up a weapon, drop the current weapon on the ground.
  • Pick up both and store them in array instead of overwriting the current weapon, and let the player change between them at will.
thanks for the help, I changed my code using the essence of your logic, again, thanks !
 
Last edited:
Top