I'm making a gamemaker game with gml. In this game I have multiple enemies (same object) on screen at the same time. I want them to all spawn a bullet at their location. But instead each enemy spawns a bullet at one single enemy. They all shoot but the bullets appear in the wrong location. I want the bullet to spawn at the location of the instance is was called for. How do I do this?

Thank you for reading my question.

Code: obj_carrier is the enemy I want to spawn from. obj_carrier_bullet is the bullet I want to spawn at location of the carrier There are multiple carriers around the stage. In the step event of the carrier following an if statement:

   instance_create(obj_carrier.x, obj_carrier.y, obj_carrier_bullet)
  • \$\begingroup\$ Please post your code, we can only guess at the issue without it. \$\endgroup\$ – Chris May 20 '13 at 1:44
  • \$\begingroup\$ Here you go. :) \$\endgroup\$ – Strokes May 20 '13 at 2:00
  • \$\begingroup\$ Where are you getting your object coordinates from? Try adding some additional code, as this function call alone doesn't provide much context. At the moment, I would say you are not getting unique object coordinates, and simply referencing the same carrier object every time. \$\endgroup\$ – Evan May 20 '13 at 14:33
  • \$\begingroup\$ If you are creating obj_carrier_bullet from obj_carrier (ie in its step event, or alarm event, or wherever), just use x and y. obj_carrier.x will create it on the first obj_carrier's x position. \$\endgroup\$ – Jeff May 20 '13 at 18:54

If you are creating/spawning the bullet from within the obj_carrier that is to create the bullet (ie inside its step event, or alarm event, etc), you can just use x and y:

instance_create(x, y, obj_carrier_bullet);

If you are creating it from a different object, you will have to figure out which object it is and create it from there (ie:

var objectThatWillCreateBullet = instance_create(random(room_width), random(room_height), obj_carrier);
instance_create(objectThatWillCreateBullet.x, objectThatWillCreateBullet.y, obj_carrier_bullet);

This is probably not what you are doing though).

If you want all obj_carrier's to create a bullet at once, you can do:

with(obj_carrier) {

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.