[Fix?] Hyperspace bug. Messed up velocity issues.

Ok. What we are doing here is messy.

What we are doing is modulating the velocity. There is also a dt
in there to try to make it not frame dependant..

The way things are done right now, we  are cascading the limit_speed with the physics model,
We can simplify it to a euler integration (It's actuallyu runge-kutta)..

What we are doung is:

v1 = v0 + adt

Basically this means that the current velocity is the last vel plus the acceleration, times the
time passed from the last instance. This is then chained to the limit speed which does:

v = (v1 - vmax)(1-3dt)

So we can right the composite form as:

v = (v0 + adt - vmax) 1-3dt) = v0 + adt - vmax - 3dtv0 - 3adt2 + 3dtvmax

-- Yes. This is hacky. I will try to play with some equasions later.
This commit is contained in:
Allanis 2013-02-27 03:45:25 +00:00
parent f6de9e8186
commit a6c758aa66
3 changed files with 7 additions and 5 deletions

View File

@ -14,9 +14,11 @@ double angle_diff(const double ref, double a) {
return (d <= M_PI) ? d : d - 2*M_PI;
}
void limit_speed(Vec2* vel, const double speed) {
if(VMOD(*vel) > speed) // Should not go faster.
vect_pset(vel, speed, VANGLE(*vel));
void limit_speed(Vec2* vel, const double speed, const double dt) {
double vmod;
vmod = VMOD(*vel);
if(vmod > speed) // Should not go faster.
vect_pset(vel, (vmod-speed)*(1.-dt*3.) + speed, VANGLE(*vel));
}
// ================

View File

@ -22,7 +22,7 @@ typedef struct Vec2_ {
double mod, angle; // Polar values.
} Vec2;
void limit_speed(Vec2* vel, const double speed);
void limit_speed(Vec2* vel, const double speed, const double dt);
// Vector manupulation.
void vect_cset(Vec2* v, const double x, const double y);

View File

@ -279,7 +279,7 @@ static void pilot_update(Pilot* pilot, const double dt) {
if(!pilot_isFlag(pilot, PILOT_HYPERSPACE))
// Should not go faster.
limit_speed(&pilot->solid->vel, pilot->ship->speed);
limit_speed(&pilot->solid->vel, pilot->ship->speed, dt);
}
// Pilot is getting ready or is in, hyperspace.