I'm trying to make a system where players can pick objects up. But I want to make sure the object is in front of their character. Right now I use CFrame to determine if its in front of the player:
local Displacement = Character.HumanoidRootPart.CFrame:pointToObjectSpace(Object.Position) if math.abs(Displacement.X) < AngleReach and Displacement.Z > -Distance and Displacement.Z < 0 then --print("The object is in front of the character. They may pick it up.") else --print("The object is behind the character. They can not pick it up.") end
But are there better more efficient ways to do this? Right now the code above runs for every object on the ground. Would I be better off with using Raycasting or even have a part that is welded to the front of the character and test if its touching an object?
What would you guys recommend?
Closed as Primarily Opinion-Based by User#19524
This question has been closed because it is a discussion about a topic focused on diverse opinions, which isn't a good fit for our Q&A format.
Why was this question closed?