Take the 2-minute tour ×
Game Development Stack Exchange is a question and answer site for professional and independent game developers. It's 100% free, no registration required.

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)
share|improve this question
    
Please post your code, we can only guess at the issue without it. –  Chris May 20 '13 at 1:44
    
Here you go. :) –  Strokes May 20 '13 at 2:00
    
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. –  Evan May 20 '13 at 14:33
    
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. –  Jeff May 20 '13 at 18:54
add comment

1 Answer

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) {
    instance_create(x,y,obj_carrier_bullet);
}
share|improve this answer
add comment

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

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