[Add] limit_speed in physics
This commit is contained in:
parent
0de847b5a4
commit
f6de9e8186
@ -14,6 +14,11 @@ double angle_diff(const double ref, double a) {
|
|||||||
return (d <= M_PI) ? d : d - 2*M_PI;
|
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));
|
||||||
|
}
|
||||||
|
|
||||||
// ================
|
// ================
|
||||||
// VEC2
|
// VEC2
|
||||||
// ================
|
// ================
|
||||||
|
@ -22,6 +22,8 @@ typedef struct Vec2_ {
|
|||||||
double mod, angle; // Polar values.
|
double mod, angle; // Polar values.
|
||||||
} Vec2;
|
} Vec2;
|
||||||
|
|
||||||
|
void limit_speed(Vec2* vel, const double speed);
|
||||||
|
|
||||||
// Vector manupulation.
|
// Vector manupulation.
|
||||||
void vect_cset(Vec2* v, const double x, const double y);
|
void vect_cset(Vec2* v, const double x, const double y);
|
||||||
// Doesn't set mod nor angle.
|
// Doesn't set mod nor angle.
|
||||||
|
@ -277,11 +277,9 @@ static void pilot_update(Pilot* pilot, const double dt) {
|
|||||||
// Update the solid.
|
// Update the solid.
|
||||||
(*pilot->solid->update)(pilot->solid, dt);
|
(*pilot->solid->update)(pilot->solid, dt);
|
||||||
|
|
||||||
if(!pilot_isFlag(pilot, PILOT_HYPERSPACE) && VMOD(pilot->solid->vel) >
|
if(!pilot_isFlag(pilot, PILOT_HYPERSPACE))
|
||||||
pilot->ship->speed)
|
|
||||||
// Should not go faster.
|
// Should not go faster.
|
||||||
vect_pset(&pilot->solid->vel, pilot->ship->speed,
|
limit_speed(&pilot->solid->vel, pilot->ship->speed);
|
||||||
VANGLE(pilot->solid->vel));
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// Pilot is getting ready or is in, hyperspace.
|
// Pilot is getting ready or is in, hyperspace.
|
||||||
|
Loading…
Reference in New Issue
Block a user