Jump to content
  • Advertisement
Sign in to follow this  
TomJakobiec

How to use vectors to approximate flaying space ship moves and be independent from FPS?

This topic is 2422 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Recommended Posts

I'm really beginner in 3D game development and I got into trouble with moving objects in my Android Java game.
The point is I'm trying to pretend that my objects has a mass this way they cannot turn in place to the right vector in 3D space.

To get this behavior I'm do things like follows (pseudo code):

vector3 spaceShipForward;
ponit3 targetPos (100,100,100);
point3 spaceShipPos (0,0,0);

loop
{
int deltaT = timer.getDelta();

Vector3 targetDirection = targetPos - spaceShipPos;
targetDirection.normalize;

// displacement is inertia vector plus turn vector mul by delta time to remove FPS impact on objects moving speed
Vecrtor3 displacement = ( spaceShipForward + targetDirection ) * deltaT;

spaceShipPos += displacement;

spaceShipForward = displacement.normalize;

targetPos.moveToSomeNewPos()
}


This algorithm has one big bad, bad issue. When FPS are high, loop iteration are very fast, then each iteration of loop works on short inertia and turn vectors. This makes the space ship more agile in target homing. When FPS are down then inertia and turn vectors are longer and space ship starts have a problem to turn into target.
When I will remove mul deltaT then of course moving speed starts to be depended for FPS rate (we do not want that smile.png.
I was trying several changes using deltaT depended factors to smooth speed and turn in various rates of FPS but I'm not happy with my solution.

I think perhaps I'm wrong with this approach, any comments?

Thank you!

Share this post


Link to post
Share on other sites
Advertisement
This is usually solved by having everything related to physics (like your moving simulation) running in a different "update" function that is executed at a fixed time step. So you won't run it in your main loop, that is frame rate dependent, but in another fixed time step loop, and you would only pick up its position and render it in the main loop.

Share this post


Link to post
Share on other sites
Sign in to follow this  

  • Advertisement
×

Important Information

By using GameDev.net, you agree to our community Guidelines, Terms of Use, and Privacy Policy.

GameDev.net is your game development community. Create an account for your GameDev Portfolio and participate in the largest developer community in the games industry.

Sign me up!