PcoWSkbVqDnWTu_dm2ix
Collapse Sidebar

Delta

InputObject

Vector3

A Vector3 describing the Delta (change) between mouse/joystick movements.

This is useful when used with the input’s InputObject/Position|position to track the position and movement of the user’s mouse/joystick, such as when you’re creating custom movement or camera scripts. Consider tracking input object changes using the Instance/Changed event or when user input changes via events such as UserInputService/InputChanged and GuiObject/InputChanged.

See also

  • InputObject/KeyCode
  • InputObject/Position
  • InputObject/UserInputState
  • InputObject/UserInputType


Code Samples


Create a Binoculars Script

This example creates a binoculars script that decreases the player’s Camera/FieldOfView|FieldOfView and UserInputService/MouseDeltaSensitivity|MouseDeltaSensitivity when a player with a UserInputService/MouseEnabled|MouseEnabled left mouse clicks. The script also points the player’s Camera towards the DataType/Vector3|Vector3 world position of the mouse click determined by the Mouse|Mouse’s Mouse/Hit|Mouse.Hit.p property.

When the player left mouse clicks again, the player’s camera reverts back to the a custom Enum/CameraType|CameraType with the same field of view and Camera/CFrame|CFrame as before the player zoomed in with the script.

While the player uses the binoculars, the script locks the player’s mouse to the center of the screen by setting the player’s UserInputType/MouseBehavior|MouseBehavior to LockCenter. The player’s camera moves when the player moves their mouse according to the InputObject/Delta|InputObject.Delta property passed by UserInputService/InputChanged|InputChanged indicating the mouse’s DataType/Vector2|Vector2 change in screen position.

In order for this example to work as expected, it should be placed in a LocalScript.


Handling InputChanged

The following example demonstrates one of many usage examples of handling user input from InputChanged depending on its type.