Kreeba

90 Degree Turns at Max Velocity in Asteroids

4 posts in this topic

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

 

Share this post


Link to post
Share on other sites

Would this resolve itself after implementing drag along each axis if acceleration wasn't applied?

Share this post


Link to post
Share on other sites

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 likes this

Share this post


Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!


Register a new account

Sign in

Already have an account? Sign in here.


Sign In Now

  • Recently Browsing   0 members

    No registered users viewing this page.