This item is not replicated across Roblox’s server/client boundary.
This property can only be read from. Attempting to write to it will cause an error.
This property indicates
DataType/CFrame of the mouse’s position in 3D space. Note that
Mouse/TargetFilter and its descendants will be ignored.
Developers can get obtain the position of Hit like so:
local position = mouse.Hit.p
Hit is often used by
Tools to fire a weapon towards the mouse in third person.
Developers looking for the
BasePart the mouse is pointing at should use
How is Mouse.Hit calculated?
The position of the Hit CFrame is calculated as the point of intersection between the mouse’s internal
DataType/Ray (an extended version of
Mouse/UnitRay) and an object in 3D space (such as a part).
The orientation of the Hit CFrame corresponds with the direction of the
local unitRayDirection = mouse.UnitRay.Direction local mouseHitDirection = mouse.Hit.lookVector -- unitRayDirection ≈ mouseHitDirection -- the vectors are approximately equal
Note, the roll of the
Workspace/CurrentCamera is not used when calculating the orientation of the Hit
The mouse’s internal ray extends for 1000 studs. If the mouse is not pointing at an object in 3D space (for example when pointing at the sky), this property will be 1000 studs away from the
Mouse.Hit Laser Beam
The code in this sample, when placed inside a
StarterPlayerScripts will draw a red laser beam between the character’s head and
Mouse/Hit at all times.
Note, this beam will pass directly through obstructions in third person as the
Mouse's raycasting is done from the
Workspace/CurrentCamera not the head.
Mouse Origin vs Mouse Hit vs CurrentCamera Position
The code below visualizes the difference between
Mouse/Origin. In order to do this, the code uses the
DataType/Vector3 positions of the hit and origin
DataType/CFrame values using
The difference is that the origin is “where the mouse came from” (its origin) and the hit is the position where the mouse hits (is when the player presses their mouse).
This example also visualizes that the mouse origin is very similar to the position of the
CurrentCamera by printing the magnitude (distance) between the two positions.