Description
The PitchClamp
property of the PlayerController
class is used to define the range within which the player's pitch (vertical look angle) can be clamped. This property is particularly useful for restricting the player's ability to look too far up or down, which can be important for maintaining a realistic or desired gameplay experience.
Usage
To use the PitchClamp
property, simply set it to a value between 0 and 180. This value represents the maximum angle in degrees that the player's pitch can reach. For example, setting it to 90 would allow the player to look straight up or down, while setting it to 45 would restrict the player's view to a more limited range.
Example
// Example of setting the PitchClamp property
PlayerController playerController = new PlayerController();
playerController.PitchClamp = 90.0f; // Allow the player to look straight up and down
// Example of using the PitchClamp property in a game loop
void Update()
{
// Assuming playerController is already initialized
float currentPitch = playerController.EyeAngles.pitch;
currentPitch = Math.Clamp(currentPitch, -playerController.PitchClamp, playerController.PitchClamp);
playerController.EyeAngles = new Angles(currentPitch, playerController.EyeAngles.yaw, playerController.EyeAngles.roll);
}