Kreeba Posted July 14, 2017 Share Posted July 14, 2017 Hi. I am working on a 2D asteroids game, and I have hit a snag with the 'standard' asteroids maths. I have implemented https://codepen.io/SitePoint/pen/rLvZrG into my game (I am using BabylonJS to render, but this isn't a babylon issue). That the problem is: Problem: Press W Key to accelerate 'up' and hold it there until you reach the maximum value. Then release the W Key and the momentum will continue. Rotate ship to 90 Degrees and hold W again. Because the Max velocity values are already met, you can never end up going 'streight'. Rather you will then cap out at a sort of 45 degree, How can I adapt the maths to be able to cancel out the y (or x) value if there is no direct thrust in that direction? Thanks Quote Link to comment Share on other sites More sharing options...
Kreeba Posted July 14, 2017 Author Share Posted July 14, 2017 Would this resolve itself after implementing drag along each axis if acceleration wasn't applied? Quote Link to comment Share on other sites More sharing options...
Kreeba Posted July 14, 2017 Author Share Posted July 14, 2017 It did. Consider this resolved. I added some drag by doing: //Drag (also corrects momentum issues) this.state.movement.x *= 0.98 this.state.movement.z *= 0.98 mattstyles 1 Quote Link to comment Share on other sites More sharing options...
mattstyles Posted July 16, 2017 Share Posted July 16, 2017 Good job finding a solution, and thanks for posting it, it'll surely help others in the same situation Quote Link to comment Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.
Note: Your post will require moderator approval before it will be visible.