3 Commits

Author SHA1 Message Date
Ray
500494f791 Update core_3d_fps_controller.c 2025-08-23 00:02:19 +02:00
Ray
1d17be6c1c Merge pull request #5137 from feive7/master
Clamp camera pitch
2025-08-22 23:41:34 +02:00
8b0cbb6f47 Clamp camera pitch 2025-08-21 11:10:13 -07:00

View File

@ -106,9 +106,9 @@ int main(void)
{
// Update
//----------------------------------------------------------------------------------
Vector2 mouse_delta = GetMouseDelta();
lookRotation.x -= mouse_delta.x*sensitivity.x;
lookRotation.y += mouse_delta.y*sensitivity.y;
Vector2 mouseDelta = GetMouseDelta();
lookRotation.x -= mouseDelta.x*sensitivity.x;
lookRotation.y += mouseDelta.y*sensitivity.y;
char sideway = (IsKeyDown(KEY_D) - IsKeyDown(KEY_A));
char forward = (IsKeyDown(KEY_W) - IsKeyDown(KEY_S));
@ -261,7 +261,10 @@ static void UpdateCameraAngle(Camera *camera)
Vector3 right = Vector3Normalize(Vector3CrossProduct(yaw, up));
// Rotate view vector around right axis
Vector3 pitch = Vector3RotateByAxisAngle(yaw, right, -lookRotation.y - lean.y);
float pitchAngle = -lookRotation.y -
lean.y;
pitchAngle = Clamp(pitchAngle, -PI / 2 + 0.0001f, PI / 2 - 0.0001f); // Clamp angle so it doesn't go past straight up or straight down
Vector3 pitch = Vector3RotateByAxisAngle(yaw, right, pitchAngle);
// Head animation
// Rotate up direction around forward axis