I decided to use a 8x8 white Frame UI on the middle of my screen as my mouse cursor, also hiding the actual cursor using UserInputService.MouseIconEnabled.
I’ve also wanted to add an interaction thing, where if your white frame UI “touches” a part, you can interact with it. Just like when a mouse hovers over a 3D part, you can useMouse.Target, instead, I want to detect if a UI hovers over one.
I’ve tried googling and rephrasing my issue, and I found nothing that could help me.
If you have any suggestions or solutions, please go ahead and comment them below. Thank you.
You should use raycasting for this. You want to shoot a ray from the camera position towards the camera direction. You can get this information in the camera.CFrame.
My game also has view bobbing on, for a realistic camera, and for some reason in first person, my mouse cursor doesn’t properly intersect because of the bobbing.
So I tried using a UI to try intersecting, but I couldn’t find any way to do this.
Edit: I will try raycasting and see if the view bobbing breaks it or not.
Well if you bob the camera then it would affect the camera’s CFrame. So if for example you shake the screen (by shaking the camera CFrame) then the intersected objects will also change during the shake.
Of course that is true with the UI as well. Actually the UI itself has no way to tell the objects behind it. Instead you could transform all objects from world to screen position and that would make it possible to intersect with the UI. But that’s bad, because you need to do this for all the objects in the scene. It doesn’t scale.
Back to the bobbing, it depends on how you want your game to act. Do you want the bobbing to affect the highlighting of items? If not, then make sure to save the actual camera CFrame (pre-bob) and use that to ray cast. Both are possible.
One more tip for raycasts. A lot of times you are not sure where your raycast hits while debugging it. I would suggest to make some marker parts that you create and destroy onRenderStepped so you can see where your raycast ends.