michaelcalkins Posted April 3, 2016 Share Posted April 3, 2016 How do you update a child sprite's angle so it points at the current position of your mouse? create function // this.player created up here this.rightArmSprite = this.game.add.sprite(0, 0, 'right-arm') this.rightArmSprite.anchor.set(.24, .2) this.ak47Sprite = this.game.add.sprite(0, 0, 'ak47') this.rightArmSprite.addChild(this.ak47Sprite) this.player.addChild(this.rightArmSprite) update function let rightArmRotation = this.game.physics.arcade.angleToPointer(this.rightArmSprite) What do I do with the angle from my right arm sprite to my mouse? Link to comment Share on other sites More sharing options...
megmut Posted April 3, 2016 Share Posted April 3, 2016 You should always anchor your sprite using sprite.anchor.setTo(0.5); then, when you add the child sprite, anchor it using anchor.setTo(0, 0); this means the sprite will be created at the centre of the man, but rotate around the top left shoulder part. Also, if you've not cropped the arm down to the pivot point, then this may also be the issue and you'll have to trial and error find the correct anchor point.. i.e: anchor.setTo(0.13, 0.22); This should fix your issue michaelcalkins 1 Link to comment Share on other sites More sharing options...
michaelcalkins Posted April 3, 2016 Author Share Posted April 3, 2016 I think I introduced a bug into my code somehow. http://imgur.com/lJCveIN http://imgur.com/vVkfb52 Link to comment Share on other sites More sharing options...
michaelcalkins Posted April 3, 2016 Author Share Posted April 3, 2016 var angleInDegrees = this.game.physics.arcade.angleToPointer(this.rightArmSprite) * 180 / Math.PI; this.rightArmSprite.angle = angleInDegrees + 90 to var angleInDegrees = this.game.physics.arcade.angleToPointer(this.player) * 180 / Math.PI; this.rightArmSprite.angle = angleInDegrees + 90 fixed the issue I was having. Once the right arm is a child of the player I was calculating the angle from the mouse incorrectly to the right arm still. It should have been calculating from the parent. Link to comment Share on other sites More sharing options...
megmut Posted April 3, 2016 Share Posted April 3, 2016 Ah good! Nice graphics man! Can't wait to see a playable version of the game, keep the forum updated on progress dude! michaelcalkins 1 Link to comment Share on other sites More sharing options...
Recommended Posts