Keyboard shortcuts

Press or to navigate between chapters

Press S or / to search in the book

Press ? to show this help

Press Esc to hide this help

Raycast

Add this in your code:

#include <engine/physics/raycast.h>

Description

Class to check collisions with a ray.

Public methods


Check

Check if a ray hits a collider.
Return true if the raycast has hit a collider.

Parameters:

  • startPosition: The start position of the ray
  • direction: The direction of the ray
  • maxDistance: The max distance of the ray
  • raycastHit: The raycastHit struct that will be filled with the hit information
bool Check(
    const Vector3& startPosition, 
    const Vector3& direction, 
    const float maxDistance, 
    RaycastHit& raycastHit)

Code sample:

// Check under the player
RaycastHit hit;
bool hasHit = Raycast::Check(
    raycastPointTransform->GetPosition(), 
    Vector3(0, -1, 0), 
    0.1f, 
    hit);

if (hasHit && hit.hitCollider.lock())
{
    // There is something under the player
}