Eraph Posted May 23, 2015 Share Posted May 23, 2015 G'day folks, I'm having a stab at making me a top-down space shoot 'em up. So far I've got a wee spaceship flying around with no friction by compounding angular velocities on the respective X and Y components whenever the thrust is used - grand, works a treat.What I'd like to do now is have the spaceship slowly come to a stop when the player presses the DOWN key - not deceleration as in reverse thrust, but to gradually come to a complete stop, velocity 0 in both the X and Y axes.So how I figure to do this is to call:this.game.physics.arcade.velocityFromAngle(this.currentVelocityAngle, this.brake);Again, that would be compounded onto the component X and Y properties of the ship velocity. The problem I'm having is that I can't figure out the angle of the current velocity of the ship. I can see the speed by using:this.game.debug.text('Speed: ' + this.body.speed, 32, 200);But there doesn't seem to be a similar property for the angle. I could use some good ol' trigonometry to calculate this, but I want to make sure it's not been done already! Link to comment Share on other sites More sharing options...
rich Posted May 24, 2015 Share Posted May 24, 2015 Yeah there isn't a property for this. I guess I could add one, but it's just a single call to atan2, so it's probably quicker to not wrap that into another function call! BTW your avatar - that was one of the best Atari ST shareware games Animal Soft ever made Link to comment Share on other sites More sharing options...
Eraph Posted May 24, 2015 Author Share Posted May 24, 2015 Cheers Rich, I woke up this morning with a fresh mind and remembered about tan2 - does the job alright. I'd be inclined to suggest it gets added somewhere for consistency's sake, it's nice to have when you're not overly familiar with (or straight-up forget because it's 1:30am) what the other libraries of JS can do.this.body.velocityAngle;this.body.velocityRotation;And yeah... BTW your avatar - that was one of the best Atari ST shareware games Animal Soft ever made I'd go as far as to say it was one of the best shareware games on the ST altogether. Good work on Phaser though! Really enjoying using it! Link to comment Share on other sites More sharing options...
Recommended Posts