Skip to content

Commit

Permalink
Merge pull request #795 from Wartori54/bird-path-fix
Browse files Browse the repository at this point in the history
Change max rotation speed to be read as degrees + cleanups
  • Loading branch information
maddie480 authored Jul 21, 2024
2 parents 5c387ef + a8589ff commit 5370422
Showing 1 changed file with 3 additions and 7 deletions.
10 changes: 3 additions & 7 deletions Celeste.Mod.mm/Patches/BirdPath.cs
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ public class patch_BirdPath : BirdPath {
// Whether to apply the fix, see `PatchBirdPathUpdate`
private bool angleFix = false;
// Maximum rad/s turn speed, see `PatchBirdPathUpdate`
private float angleFixMaxRotation = 1;
private float angleFixMaxRotation = MathF.PI / 3; // Default to 60 deg second
// If this entity is placed in a vanilla map we will forcibly disable all changes
// Note that `angleFix` is false by default so that will also apply in vanilla
private bool inVanilla = false;
Expand All @@ -46,7 +46,7 @@ public patch_BirdPath(EntityID id, Vector2 position, Vector2[] nodes, bool onlyO
public void ctor(EntityID id, EntityData data, Vector2 offset) {
orig_ctor(id, data, offset);
this.angleFix = data.Bool("angle_fix");
this.angleFixMaxRotation = data.Float("angle_fix_max_rotation_speed");
this.angleFixMaxRotation = MathF.Abs(data.Float("angle_fix_max_rotation_speed").ToRad());
}

#pragma warning disable CS0626
Expand Down Expand Up @@ -76,11 +76,7 @@ public float CalcAngle() {
} else {
float maxTurnSpeed = angleFixMaxRotation * Engine.DeltaTime;
float newAngle = Calc.AngleLerp(this.speed.Angle(), oldAngle, 0.5F);
if (Calc.AbsAngleDiff(newAngle, oldAngle) > maxTurnSpeed) {
oldAngle += maxTurnSpeed * -Calc.SignAngleDiff(newAngle, oldAngle);
} else {
oldAngle = newAngle;
}
oldAngle = Calc.AngleApproach(oldAngle, newAngle, maxTurnSpeed);
}

return oldAngle + MathF.PI/2;
Expand Down

0 comments on commit 5370422

Please sign in to comment.