Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 7513089
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 30, 20262026-05-30T00:04:05+00:00 2026-05-30T00:04:05+00:00

Im building a small space shooter game. I have how ever stubbed on a

  • 0

Im building a small space shooter game. I have how ever stubbed on a math problem when it come to the space physics.

Describing this with words is following:
There is a max speed.
So if you give full full speed you ship will move with this over the screen over and over again like in the old asteroids games.
If then release the rocket boost you ship should be keep moving with that speed over the screen.

Then the tricky part where Im stuck right now.

If you rotate the ship ANY angle and gives boost again the ship should try to get to this direction and NEVER surpas the max speed when it comes to how fast it is moving. so my question is. anyone have a good idea formula for this issue? feels like it has been done before if you know what to look for. 🙂

Ill add this small image to illustrate what is tried to be done with some vector calculations.
Max speed movement with force

Red ring: Max speed

Green line: current ship direction.

Black line: direction(s) and how fast the ship is moveing in x and y.

Black ring: origin of movement.

Can illustrate it but hard to find a good math solution for this. 🙂

EDIT

This is the code Im using right now in every frame. It gives movement to the ship but does not give the force of movement the user has to counter-react with its rocket boosters to get the ship to stop or slow down. With this it stops the instant you release the accelerating speed for the ship.

    //Calculates ship movement rules
var shipVelocityVec = GetVectorPosByAngle(shipMoveSpeed, shipRotationAngle);
var shipUnitVec =$V([Math.cos(shipRotationAngle),Math.sin(shipRotationAngle),0]);
var rawAccel = shipAccelSpeed / shipMass;
var scale = (shipUnitVec.dot(shipVelocityVec))/(shipTopSpeed * shipTopSpeed);
var v1 = shipUnitVec.subtract(shipVelocityVec.multiply(scale));
var finalAccelVec = v1.multiply(rawAccel);
console.log(finalAccelVec);

//move ship according to rules
var shipPosVector = $V([shipxPos, shipyPos, 0]);
var movementVector =  shipPosVector.add(finalAccelVec);
shipxPos = movementVector.elements[0];
shipyPos = movementVector.elements[1];

To give the acceleration speed the user has to keep the button pressed. the instance the user releases the button the acceleration is set to zero and have to boost over again to give maximum acceleration throttle.

Solution found! Posted it here how it was done.

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-30T00:04:06+00:00Added an answer on May 30, 2026 at 12:04 am

    @BlueRaja’s solution should work, although you will get an abrupt change in behavior when you hit the max speed.

    If you want a solution with no “seams”, I believe you can do what you’re looking for by adding the right kind of adjustment to the acceleration, as follows:

    ship_unit_vec = [cos(ship_angle), sin(ship_angle)]
    raw_accel = (engine_thrust / ship_mass)
    
    scale = dot_product(ship_unit_vec, ship_velocity_vec) / max_speed^2
    
    final_accel_vec = raw_accel * (ship_unit_vec - scale * ship_velocity_vec)
    

    Notes:

    • If |ship_velocity_vec|<<max_speed, the scale * ship_velocity_vec component is negligable.
    • If |ship_velocity_vec|==max_speed, the scale * ship_velocity_vec component cancels all additional acceleration in the “wrong” direction, and aids acceleration in the “right” direction.
    • I’ve never tried this out, so I don’t know how it will feel to the player…

    More generally, if there are more sources of acceleration than just the ship thrusters, you can add them all together (say, as raw_accel_vec), and perform the above operation all at once:

    scale_forall = dot_product(raw_accel_vec, ship_velocity_vec) / max_speed^2
    final_accel_vec = raw_accel_vec - scale_forall * ship_velocity_vec
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I am building a small Space Invaders type game. Or at least trying to.
Im building a small webshop and have run into a problem. The company which
I'm building this small java applet in which I need a JPanel which will
I'm building small one page application with rails 3.1 mongodb and backbonejs. I have
First, I only have experience building small-medium sized websites with php so forgive me
I am building a small dropdown menu with jQuery, but i am have a
I'm building a small app that gives me the free space available on my
I'm having this weird problem with this website I just started building. I want
I'm building a small experiment in php/javascript, where people have to rate the familiarity
Im building a small application and I have some click events binded to some

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.