From JC2-MP Documentation
|Prototype||Physics:Raycast(Vector3 position, Vector3 direction, number minDistance, number maxDistance)|
|Prototype||Physics:Raycast(Vector3 position, Vector3 direction, number minDistance, number maxDistance, boolean ignoreLocal)|
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. minDistance is how far out from the start point before the ray begins, set at 0 to begin immediately.
If ignoreLocal (default true) is set to true, raycast will pass through LocalPlayer and the vehicle he is in.direction is a normalized Vector3; for example,
Camera:GetAngle() * Vector3.Forward
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.
GetAimTarget returns a similar result: Lua/Tutorials/Reference/GetAimTarget