Jump to content

Reset bullet to group member position


WitheringTreant
 Share

Recommended Posts

Hey,

 

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

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.
Note: Your post will require moderator approval before it will be visible.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

Loading...
 Share

  • Recently Browsing   0 members

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