Windows How do I make collision with ammo pickup destroy the ammo pickup

M

MagicMushroom

Guest
Hello, I've only just recently been having a go with game maker and am having some difficulty getting the ammo pickup working. Everytime I collide with the ammo it will keep increasing the amount of ammo I have and won't stop until I move away. I want it so that after the player collides with it the ammo will increase by x amount and the pickup itself gets destroyed. I have tried many diffrent times diffrent ways but none of them are destroying the ammo pickup when I collide with it or the ammo pickup or player will be destroyed once the game begins even when not touching it.
 

Perseus

Not Medusa
Forum Staff
Moderator
Use a function that returns the id of the colliding ammo pickup instance. Use a with construction to execute actions from this instance's scope.

Code:
with (instance_place(x, y, obj_ammo)) {
   instance_destroy();
   global.ammo += 5;
}
If the ammo variable is not a global variable but an instance variable of the player object, use other.ammo as inside a with construction, the other keyword refers to the instance calling the with construction, i.e., the player object in this case.

You could alternatively use a Collision event. To destroy the colliding instance, do this:

Code:
with (other) {
   instance_destroy();
}
global.ammo += 5; // or simply `ammo` if it's an instance variable
Inside the Collision event, other refers to the colliding instance. For further information, read: https://docs.yoyogames.com/source/dadiospice/002_reference/001_gml language overview/keywords.html
 
D

dj_midknight

Guest
in the collision code include

instance_destroy();

If you are colliding from the player side use

with(other) instance_destroy();
 
Top