I'm using GameMaker to make my game and I'm trying to get the player bullet to fire out of the players gun but for some reason even though I checked 'relative', the bullet is still being created at the top of the room.

Why? How could I have the bullet created relative to the player?


The relative label can give different results, depending on where used. When an object is created relatively to another object, it means the x and y coordinates you are giving as parameters will be summed to the object calling the Create Instance function. You can achieve this in different ways.

Fix your function

Since you want the bullet being created at player's position, you should call the Create Instance from within the player object. If you are calling the function from another object, you will get wrong results.

Delegate the function

You can also put the Create Instance function anywhere you want, as long as the Applies to field is referring the player object:

enter image description here

To do so, from the Applies to field select "Object", then choose your player object from the list, and you're done.

Use absolute coordinates

Maybe not the best solution, but it will work as well. Instead of creating the bullet relatively, create it at an absolute position (uncheck the relative field) and set such position as the player's: use oPlayer.x and oPlayer.y as x and y coordinates (change the oPlayer object name according to your project).

That's it. Let me know if something isn't working, I'll try to help you. Also, if you could provide some info such as a screenshot of the functions inside your object, we may take a deeper look to solve your issue.

  • \$\begingroup\$ Thanks for the answer @liggiorgio, here is a screenshot to better show you what is going on: imgur.com/a/64wBH \$\endgroup\$ – F.Wolf Sep 16 '16 at 19:07
  • \$\begingroup\$ Try this: delete the Set variable block on top of the stack, and put a Check variable instead of it. So you'll have: "If can_shoot is equal to true" "Set can_shoot to false, create instance, set Alarm 0 to 15" \$\endgroup\$ – liggiorgio Sep 16 '16 at 23:29
  • \$\begingroup\$ 5 how do i make a check variable? \$\endgroup\$ – F.Wolf Sep 17 '16 at 4:48
  • \$\begingroup\$ Take a look at the Yoyo Docs and read about changing and testing the value of a variable \$\endgroup\$ – liggiorgio Sep 17 '16 at 16:13
  • \$\begingroup\$ If you're fine with this, you can mark the answer as right, according to the community rules \$\endgroup\$ – liggiorgio Sep 17 '16 at 16:18

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.