Page 1 of 2

Selector Raycast Inaccurate [SOLVED]

Posted: Wed Jun 21, 2023 5:55 pm
by ojh.games
Hello,

I have an issue where the RayCast is completely inaccurate making interacting with Usables extremely difficult. I am using the CInemachineSelector.cs posted on the forum, but the issue also happens with the regular Selector.

I have enabled a Debug.DrawLine to show the issue.

As you can see in the scene view the red debug cast is intersecting with the sphere this is causing the selector UI to display in the game view, even though I am not looking directly at the sphere.

Any ideas what is happening?

Re: Selector Raycast Inaccurate

Posted: Wed Jun 21, 2023 10:45 pm
by Tony Li
Hi,

Let's look at the regular Selector. What are the settings on your Selector component?

Re: Selector Raycast Inaccurate

Posted: Thu Jun 22, 2023 10:13 am
by ojh.games
Hey, thanks for the reply!

I'm having the same result with both the regular selector and Cinemachine one. Here are the settings:

Re: Selector Raycast Inaccurate

Posted: Thu Jun 22, 2023 3:40 pm
by Tony Li
Would it be possible for you to send reproduction steps or a reproduction project to tony (at) pixelcrushers.com?

I'm not sure how to reproduce the issue. I suspect it might have something to do with what the Selector thinks are the camera or screen bounds.

Have you also checked How To: Fix Selector and Proximity Selector Issues?

Re: Selector Raycast Inaccurate

Posted: Thu Jun 22, 2023 3:53 pm
by ojh.games
I've just realised, my game is set to 4:3 aspect ratio, I tried setting it to 16:9 and that sorted the issue out. So, it seems to be an aspect ration problem.

Re: Selector Raycast Inaccurate

Posted: Thu Jun 22, 2023 4:01 pm
by Tony Li
I'll check that out now.

Re: Selector Raycast Inaccurate

Posted: Thu Jun 22, 2023 4:18 pm
by Tony Li
I just tested multiple aspect ratios, including 4:3, and they seem to work correctly.

The raycast uses this ray to do a raycast:

screenCenter = Vector3(Screen.width / 2, Screen.height / 2)
Camera.main.ScreenPointToRay(screenCenter)

Would it be possible for you to send me a reproduction project?

Re: Selector Raycast Inaccurate

Posted: Thu Jun 22, 2023 6:09 pm
by ojh.games
Thanks, I have sent you an email with the project files.

Re: Selector Raycast Inaccurate

Posted: Thu Jun 22, 2023 10:19 pm
by Tony Li
Hi,

Thanks for sending the repro project.

The issue is because your camera is rendering to a render texture. The render texture has a different resolution from the screen, but your Selector's Select At dropdown is set to Center Of Screen. You can resolve this by overriding GetSelectionPoint() in your CinemachineSelector script:

Code: Select all

        protected override Vector3 GetSelectionPoint()
        {
            return new Vector3(320, 240);
        }

Re: Selector Raycast Inaccurate

Posted: Fri Jun 23, 2023 8:39 am
by ojh.games
You are absolutely right! I feel daft for missing that, thanks very much! That has saved me from a lot of frustration.