I made a system for detecting if a player is looking at a certain part, I would like to optimize it or make it more efficient.
Any help / advice is appreciated!
Logic:
- First I use touch detection - if a player is close enough to the part.
- Then, while a player is close to the part - connect to WorldToScreenPoint function to see if a part can be visible on screen. This function is looping until the player is no longer close to the part.
- If a part is visible on screen - connect to Raycast function to detect if the part is actually visible. This function is triggered by WorldToScreenPoint once.
I would also like to know when a player is done looking at the part, but I figured looping raycast would be expensive(?). Currently I use WorldToScreenPoint on the client to do that, once they actually had a view of the part (detected with raycast).
Any suggestions? Changes?
TIA