CreateRay
Description
int CreateRay( const Vector& position, const Vector& direction, float length)
Creates a ray with the specified position, direction and length. The return value contains the index of the ray in a list stored by the object. The ray's are cast in the physical space of the world, and as such will only collide with collision object's (not visibly rendered objects)
Parameters:
position - position of the ray
direction - direction of the ray
length - length of the ray
Example Usage:
This function creates a persistent raycast that can be queried at any point to check if an intersection is occurring.
To query a ray's intersection state, simply call 'RayHasIntersection', a member of the Object@ class, like so. For example, the following script creates a ray and returns the ray's intersection height:
Vector rayOffset;
Vector objectPosition;
float desiredY;
int groundCheckRay = -1;
Vector intersect; // where we are hitting the ground
void Initialize( Object@ object)
{
// create rays
Vector rayPos;
Vector rayDir( 0, -1, 0);
// we'll cast from the center of the object to be safe
rayPos = object.GetBoundingBoxCenter();
Print("ray position: " + rayPos.x + " " + rayPos.y + " " + rayPos.z);
// create the ray to cast down for 15 meters (just to be safe)
groundCheckRay = object.CreateRay( rayPos, rayDir, 15);
}
float GetControllerVariableFloat( Object@ object, const String& in name)
{
if (name == "GroundHeight")
{
// check for collision
if (object.RayHasIntersection( groundCheckRay))
{
intersect = object.GetRayIntersection( groundCheckRay);
//intersect.y is our ground position
Print("object intersecting at " + intersect.y);
return intersect.y;
}
return 0;
}
return 0;
}
