Description
The Velocity
property of the Mouse
class provides the current velocity of the mouse cursor. This is a static property, meaning it can be accessed without instantiating the Mouse
class. The velocity is represented as a Vector2
, which contains the horizontal and vertical components of the cursor's movement speed.
Usage
To access the current velocity of the mouse cursor, use the Mouse.Velocity
property. This can be useful for determining how fast the mouse is moving across the screen, which can be used in various input handling scenarios, such as adjusting the sensitivity of camera movement in a game.
Example
// Example of accessing the mouse velocity
Vector2 currentMouseVelocity = Mouse.Velocity;
// Use the velocity to adjust camera movement
float cameraSensitivity = 0.5f;
Vector3 cameraMovement = new Vector3(currentMouseVelocity.x, currentMouseVelocity.y, 0) * cameraSensitivity;
// Apply the camera movement to the camera's position
Camera.Position += cameraMovement;