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