qbcore-framework / qb-smallresources

A compilation of small resources combined into one
GNU General Public License v3.0
49 stars 342 forks source link

raycast functions #451

Closed bicatcho11 closed 3 months ago

bicatcho11 commented 6 months ago

Describe Pull request

This code provides utility functions for game development in a 3D environment using Lua scripting. Here's a brief explanation:

GetForwardVector:
    This function calculates the forward vector based on the given rotation. It converts rotation angles to radians and computes the vector using trigonometric functions.

RayCast:
    This function performs a swept sphere raycast in the game world. It utilizes the StartShapeTestSweptSphere function with the provided origin, target, options, ignoreEntity, and radius parameters.

GetEntityPlayerIsLookingAt:

    This function determines the entity that the player is looking at within a specified distance. It calculates the forward vector of the player's camera and casts a ray in that direction. If a collision occurs, it retrieves information about the hit entity.

    The IsInVehicle condition adjusts the casting distance based on whether the player is in a vehicle or not.

    The results include the target entity, its type, and the coordinates of the hit point. The function also exports these functionalities, making them accessible from other parts of the game code.

These functions can be useful for game mechanics like targeting, interaction, or any feature where determining the player's line of sight and the entities in that direction is essential. The exported functions (GetForwardVector, RayCast, and GetEntityPlayerIsLookingAt) can be called from other scripts or game systems. If your PR is to fix an issue mention that issue here

Questions (please complete the following information):

github-actions[bot] commented 4 months ago

This PR has had 60 days of inactivity & will close within 7 days