Laumark 0 Report post Posted May 11, 2016 I'm making a game with Asteroid like controls, but I'm in doubt about how to move the sprite in the direction it is facing. What's the easiest way to do this? Quote Share this post Link to post Share on other sites
mattstyles 667 Report post Posted May 11, 2016 Sorry for the short answer but have a look at using vectors and vector-based maths rather than cartesians points to move your sprites around, it greatly simplifies this type of movement. Many physics libraries can help you out. Quote Share this post Link to post Share on other sites
Laumark 0 Report post Posted May 11, 2016 Cool, thanks. I will. Pixi doesn't have anything like that? Quote Share this post Link to post Share on other sites
mattstyles 667 Report post Posted May 11, 2016 Nope, pixi just draws stuff really really fast! Actually it does interactive stuff too but thats by-and-by. I can vouch for P2 and also matterJS, both allow any rendering front-end to be bolted on (not all physics libraries do, some like to be tied to the rendering, which, in my opinion is plain wrong, do one thing well), in my experience P2 was easier to integrate, its a very powerful package. Both libraries have a pixi example in their source repos. You should be able to find examples of bolting either physics lib and pixi together, or if you know phaser then phaser packages P2 if you dont mind using slightly older versions. If you want to roll your own though, a simplified physics library just to help you move stuff around, its not too difficult (if you know your maths a bit) and a good exercise. The physics only gets hard when you want a fairly realistic simulation, stuff like collisions and everything can get hairy, just moving around isn't too difficult. Quote Share this post Link to post Share on other sites
SebastianNette 68 Report post Posted May 12, 2016 You don't need a physics library for that. Simple trigonometry is enough. function move(object, distance) { object.x = object.x + distance * Math.cos(object.rotation); object.y = object.y + distance * Math.sin(object.rotation); } https://jsfiddle.net/11av8s0m/ 1 coelacanth reacted to this Quote Share this post Link to post Share on other sites
ivan.popelyshev 1071 Report post Posted May 12, 2016 Better use Ticker and mutiply that thing on delta time. Quote Share this post Link to post Share on other sites