DudeshootMankill Posted May 12, 2016 Share Posted May 12, 2016 Heya, im doing the angle to pointer thing, but i need to restrict the rotation of the sprite so that it can only go within specific degrees. I was hoping someone could help me out here? I'd be greatful. And sorry if it's a very obvious thing. Link to comment Share on other sites More sharing options...
mattstyles Posted May 12, 2016 Share Posted May 12, 2016 Quick google search will throw up about a million hits for finding the angle between two points, and a fair number for angles between vectors. This gist seems to be about what you want. All you need to do is transform your pointer from screen space into world space and you're all set, that's normally trivial. Link to comment Share on other sites More sharing options...
DudeshootMankill Posted May 12, 2016 Author Share Posted May 12, 2016 game.physics.arcade.angleBetween(player, game.input.activePointer); gives me a rather odd number ranging from about 3 to 0,111111. Is this because my pointer is in screen space? Link to comment Share on other sites More sharing options...
Milton Posted May 12, 2016 Share Posted May 12, 2016 Probably radians? Try multiplying by 180/pi. Link to comment Share on other sites More sharing options...
DudeshootMankill Posted May 12, 2016 Author Share Posted May 12, 2016 Thank you both, this turned out nicely. Link to comment Share on other sites More sharing options...
DudeshootMankill Posted May 13, 2016 Author Share Posted May 13, 2016 Well, i've hit another snag. I've given my player sprite a child, this is the gun and it tracks the mouse. Now if i turn left, and use scale.x -1 to flip the sprite the gun gets inverted aswell. I've got this so far if (cursorPos > 140) { arrow.rotation = game.physics.arcade.angleToPointer(player) - Math.PI; }; The gun is aimed to the left side but the rotation is inverted of the mouse position. Hope anyone could point me in the right way again? Link to comment Share on other sites More sharing options...
mattstyles Posted May 13, 2016 Share Posted May 13, 2016 I'm not an expert with Phaser or grouping but sounds like those elements should not be grouped together like that, or, more specifically, you'd want to only flip your player sprite and not the gun sprite attached to them. Maybe you could group them so they are siblings and move their container around? That way they both share a common parent which tracks movement etc but you can only flip the actual player sprite inside when necessary. The gun would rotate as you currently are doing, presumably the gun flips too when the angle is within a certain range. Link to comment Share on other sites More sharing options...
Recommended Posts