|
Returns
|
table
|
|
Prototype
|
Physics:Raycast(Vector3 position, Vector3 direction, number minDistance, number maxDistance)
|
|
Description
|
No description
|
Description
Casts a ray at
position, fired in direction
direction. A raycast is like shooting a bullet from a gun; it returns information about the point at which the ray collides with the world or an object. If nothing is encountered when the ray's length reaches
maxDistance, the point at
maxDistance is returned instead, which will be a point in midair. If the ray hits a JC2-MP object, it will be returned as part of the result.
direction is a normalized
Vector3; for example,
Camera:GetAngle() * Vector3.Forward
will create a direction vector that aims forward from the camera.
The result is similar to
GetAimTarget.
Bug: The ray seems to ignore everything if
maxDistance is high enough (1000 is safe, 5000 is too long).
The table returned may contain the following elements:
- number distance: the distance, in metres, that the final position is from the origin.
- Vector3 position: the position hit by the ray; if the ray failed to hit anything, this will be equal to position + direction * maxDistance.
- Vector3 normal: the vector perpendicular to the surface, also known as the normal, hit by the raycast.
- object entity: the JC2-MP entity the ray hit, if it hit one.
See also
GetAimTarget returns a similar result:
Lua/Tutorials/Reference/GetAimTarget