Skip to content

Instantly share code, notes, and snippets.

@johnsoncodehk
Last active May 19, 2026 15:47
Show Gist options
  • Select an option

  • Save johnsoncodehk/2ecb0136304d4badbb92bd0c1dbd8bae to your computer and use it in GitHub Desktop.

Select an option

Save johnsoncodehk/2ecb0136304d4badbb92bd0c1dbd8bae to your computer and use it in GitHub Desktop.
Unity Clamp Angle
public static float ClampAngle(float angle, float min, float max) {
float start = (min + max) * 0.5f - 180;
float floor = Mathf.FloorToInt((angle - start) / 360) * 360;
return Mathf.Clamp(angle, min + floor, max + floor);
}
@YaroslavFur

YaroslavFur commented Apr 24, 2023

Copy link
Copy Markdown

<3 (heart)

@Trapperfly

Copy link
Copy Markdown

You are amazing <3 Thank you

@Vladimir-Maks

Copy link
Copy Markdown

you helped me solve my problem with clamping angles in godot. Thank you so much.

@SergeiKuznetcov1

Copy link
Copy Markdown

thanks

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment