Mike018 Posted May 5, 2016 Share Posted May 5, 2016 I have an object that bounces around in all directions via arcade physics and every 10 seconds, it changes speed. But every time it changes speed, it will not continue in it's current path, but change directions based on the initial velocity. How can I increase the speed while maintaining it's current path? var speedChange = 50; this.blade1.body.velocity.x = this.enemySpeed + speedChange; this.blade1.body.velocity.y = this.enemySpeed + speedChange; this.enemySpeed += speedChange; Link to comment Share on other sites More sharing options...
VitaZheltyakov Posted May 5, 2016 Share Posted May 5, 2016 this.body.velocity.x = Math.cos(this.rotation) * this.speed_new; this.body.velocity.y = Math.sin(this.rotation) * this.speed_new; or this.physics.velocityFromRotation(this.rotation, this.speed_new, this.body.velocity); drhayes 1 Link to comment Share on other sites More sharing options...
Mike018 Posted May 6, 2016 Author Share Posted May 6, 2016 1 hour ago, VitaZheltyakov said: this.body.velocity.x = Math.cos(this.rotation) * this.speed_new; this.body.velocity.y = Math.sin(this.rotation) * this.speed_new; or this.physics.velocityFromRotation(this.rotation, this.speed_new, this.body.velocity); Both of those seem to not be working. Once the speed changes, the objects will lose their y velocity and just move left and right. Also, the x velocity will not continue in the same direction all the time. Link to comment Share on other sites More sharing options...
VitaZheltyakov Posted May 6, 2016 Share Posted May 6, 2016 8 hours ago, Mike018 said: Both of those seem to not be working. Once the speed changes, the objects will lose their y velocity and just move left and right. Also, the x velocity will not continue in the same direction all the time. You can not test my code? Link to comment Share on other sites More sharing options...
Tom Atom Posted May 6, 2016 Share Posted May 6, 2016 As velocity is Phaser.Point, you can call its setMagnitude: this.body.velocity.setMagnitude(speed); drhayes and Mike018 2 Link to comment Share on other sites More sharing options...
Recommended Posts