Jump to content

Reset bullet to group member position


Recommended Posts



I've recently made a group to contain parts of the player's tank, including a turret.


I noticed that turret.x and turret.y are not returned as gameworld coordinates, but coordinates relative to the group position.

In this case, turret.x = 20 and turret.y = 40, and the returned values are not affected by group rotation or group position.


Basically, I need to get the gameworld X and Y position of the turret, when group rotation is taken into account. That way I could reset the bullet on top of the turret when it's firing. Group rotation needs to be taken into account because the tank can rotate, thus changing the turret positioning around the group's center (pivot).


// This is how i first create the group and then the turret as it's child

player_tank_group = game.add.group();

player_tank_group.x = 500;

player_tank_group.y = 500;

player_tank_group.create(20, 40, 'turret_medium_yellow'); //parts are added as coordinates relative to the group position

turret = player_tank_group.getAt(0);


// then rotate the group

player_tank_group.rotation = 1;


// then i need to get these 2 values, reflecting group rotation and game world position.

turret.x in gameworld coordinates

turret.y in gameworld coordinates


Does anyone have any idea how to achieve this? I need this and i've been stuck for a while with it.

Link to comment
Share on other sites


  • Recently Browsing   0 members

    • No registered users viewing this page.
  • Create New...