Description
The Mouse.Delta
property provides the change in the local client's cursor position since the last frame. This is useful for detecting mouse movement and implementing features that rely on mouse motion, such as camera rotation or object dragging in a game environment.
Usage
To use the Mouse.Delta
property, simply access it as a static property of the Mouse
class. It returns a Vector2
representing the change in the cursor's position on the screen since the last frame.
Example
// Example of using Mouse.Delta to rotate an object based on mouse movement
public class PlayerController : Component
{
public override void Update()
{
// Get the mouse delta
Vector2 mouseDelta = Mouse.Delta;
// Use the mouse delta to rotate the player
RotatePlayer(mouseDelta);
}
private void RotatePlayer(Vector2 delta)
{
// Assuming a simple rotation logic based on mouse movement
float rotationSpeed = 0.1f;
float yaw = delta.x * rotationSpeed;
float pitch = delta.y * rotationSpeed;
// Apply rotation to the player
Transform.Rotation *= Rotation.FromYawPitchRoll(yaw, pitch, 0);
}
}