Zackorz Posted January 21, 2016 Share Posted January 21, 2016 Hi, I want to move some objects ( i spawn one every 2 seconds) to a specific point and spin them, so the front of the image should be always pointing towards the goal destination. I wonder what method is the best here. I started using a "tween", but i didnt like the smooth movement, i want it to be linear. Also i didnt know how to spin the image into the correct position. Link to comment Share on other sites More sharing options...
Cudabear Posted January 21, 2016 Share Posted January 21, 2016 Tweens are your best bet. You can change the movement style (2nd parameter in creating the tween) to "Linear" to achieve the steady movement you're asking for. As for the spinning, you'll need to manually do some math to figure out what the rotation should be upon arriving to the destination. Then, add a tween to the sprite's rotation to achieve it. Can't remember the math off the top of my head, but it's some basic trigonometry. Zackorz 1 Link to comment Share on other sites More sharing options...
Zackorz Posted January 21, 2016 Author Share Posted January 21, 2016 22 minutes ago, Cudabear said: Tweens are your best bet. You can change the movement style (2nd parameter in creating the tween) to "Linear" to achieve the steady movement you're asking for. As for the spinning, you'll need to manually do some math to figure out what the rotation should be upon arriving to the destination. Then, add a tween to the sprite's rotation to achieve it. Can't remember the math off the top of my head, but it's some basic trigonometry. Still no linear movement. Im doing something wrong, but i cant figure out what it is. This is my code: var demotweeen = this.add.tween(mytween.to({x:400,y:400},500, 'Linear'); demotweeen.start(); Ok i got my error, i used it in a loop. Therefore the way was recalculated new every loop and it takes 500 ms every time new. "Linear" is working now, thanks. Link to comment Share on other sites More sharing options...
Recommended Posts