Package net.risingworld.api.utils
Class RaycastResult
java.lang.Object
net.risingworld.api.utils.RaycastResult
Represents the result of a raycast.
-
Method Summary
Modifier and TypeMethodDescriptionGets the collision normal, i.e the normal of the surface the ray hit.
This normal is already normalized.Gets the collision point, i.e the position where the ray hit a collider.
Note: If you want to get the world position of the hit object itself instead, seegetObjectPosition()
float
Gets the distance between the player (or more precisely, the origin of the ray) and the collision point.int
Gets the internal instance ID of the underlying Unity GameObject that was hit.int
getLayer()
Gets the hit layer.Gets the chunk coordinates where the element is located that was hit by this ray.long
Gets the global ID (of the element the ray collided with).Gets the world position of the element that was hit by this ray.int
Gets the triangle index of the hit element mesh.boolean
Gets whether or not a collision occurred.boolean
Gets whether or not the hit collider was a "trigger" (i.e a ghost collider).toString()
Gets a String representation of this RayCastResult.
-
Method Details
-
hasCollision
public boolean hasCollision()Gets whether or not a collision occurred. Usually it is not necessary to call this method, since in case that no collision occurred, there wouldn't be aRaycastResult
object (i.e the callback result would be null).- Returns:
- true if this object holds a result, false if not.
-
getDistance
public float getDistance()Gets the distance between the player (or more precisely, the origin of the ray) and the collision point. ReturnsFloat.MAX_VALUE
if no collision occurred (seehasCollision()
.- Returns:
- the distance to the collision point.
-
getLayer
public int getLayer()Gets the hit layer. If no collision occurred, this methods returns 0.- Returns:
- the layer of the object that was hit.
- See Also:
-
getCollisionPoint
Gets the collision point, i.e the position where the ray hit a collider.
Note: If you want to get the world position of the hit object itself instead, seegetObjectPosition()
- Returns:
- the collision position as a
Vector3f
.
-
getCollisionNormal
Gets the collision normal, i.e the normal of the surface the ray hit.
This normal is already normalized.- Returns:
- the collision normal as a normalized
Vector3f
, or null if no collision occurred.
-
getInstanceID
public int getInstanceID()Gets the internal instance ID of the underlying Unity GameObject that was hit. The instance ID identifies the actual internal object. It's neither persistent nor identical between different players!- Returns:
- the internal Unity object instance ID (may be positive or negative).
- See Also:
-
isTrigger
public boolean isTrigger()Gets whether or not the hit collider was a "trigger" (i.e a ghost collider).- Returns:
- true if the hit collider was a trigger, false if it's a solid collider.
-
getTriangleIndex
public int getTriangleIndex()Gets the triangle index of the hit element mesh.- Returns:
- the hit triangle index.
-
getObjectGlobalID
public long getObjectGlobalID()Gets the global ID (of the element the ray collided with). This only works for elements which have an id (e.g objects, construction elements, plants, npc etc).- Returns:
- the element type id, or -1 if no collision occurred or if the object does not have a type id (e.g terrain, water, grass etc).
- See Also:
-
getObjectPosition
Gets the world position of the element that was hit by this ray. Not to be confused with the collision point, which is the actual point where the collision occurred.- Returns:
- the world position of the hit element.
- See Also:
-
getObjectChunkPosition
Gets the chunk coordinates where the element is located that was hit by this ray. If we hit an object (like furniture), a construction element (like a block) or a plant, we can use the chunk position in combination withgetObjectGlobalID()
to get the object instance (e.g fromWorld.getObject(long, int, int, int)
orWorld.getConstructionElement(long, int, int, int)
.- Returns:
- the chunk coordinates of the hit element.
- See Also:
-
toString
Gets a String representation of this RayCastResult.
-