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.
DataType/CFrame of the mouse’s position in 3D space.
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
DataType/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
The orientation of the Hit
DataType/CFrame corresponds with the direction of the
local unitRayDirection = mouse.UnitRay.Direction local mouseHitDirection = mouse.Hit.lookVector -- unitRayDirection ≈ mouseHitDirection -- the vectors are aproximately equal
Note, the roll of the
Workspace/CurrentCamera is not used when calculating the orientation of the Hit
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), Mouse.Hit 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.