Selector Raycast Inaccurate [SOLVED]

Announcements, support questions, and discussion for the Dialogue System.
ojh.games
Posts: 5
Joined: Wed Jun 21, 2023 5:47 pm

Selector Raycast Inaccurate [SOLVED]

Post 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?
Attachments
issue.png
issue.png (979.6 KiB) Viewed 379 times
Last edited by ojh.games on Fri Jun 23, 2023 8:39 am, edited 1 time in total.
User avatar
Tony Li
Posts: 21681
Joined: Thu Jul 18, 2013 1:27 pm

Re: Selector Raycast Inaccurate

Post by Tony Li »

Hi,

Let's look at the regular Selector. What are the settings on your Selector component?
ojh.games
Posts: 5
Joined: Wed Jun 21, 2023 5:47 pm

Re: Selector Raycast Inaccurate

Post 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:
Attachments
CinemachineSelector.png
CinemachineSelector.png (37.94 KiB) Viewed 372 times
Selector.png
Selector.png (43.75 KiB) Viewed 372 times
User avatar
Tony Li
Posts: 21681
Joined: Thu Jul 18, 2013 1:27 pm

Re: Selector Raycast Inaccurate

Post 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?
ojh.games
Posts: 5
Joined: Wed Jun 21, 2023 5:47 pm

Re: Selector Raycast Inaccurate

Post 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.
User avatar
Tony Li
Posts: 21681
Joined: Thu Jul 18, 2013 1:27 pm

Re: Selector Raycast Inaccurate

Post by Tony Li »

I'll check that out now.
User avatar
Tony Li
Posts: 21681
Joined: Thu Jul 18, 2013 1:27 pm

Re: Selector Raycast Inaccurate

Post 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?
ojh.games
Posts: 5
Joined: Wed Jun 21, 2023 5:47 pm

Re: Selector Raycast Inaccurate

Post by ojh.games »

Thanks, I have sent you an email with the project files.
User avatar
Tony Li
Posts: 21681
Joined: Thu Jul 18, 2013 1:27 pm

Re: Selector Raycast Inaccurate

Post 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);
        }
ojh.games
Posts: 5
Joined: Wed Jun 21, 2023 5:47 pm

Re: Selector Raycast Inaccurate

Post 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.
Post Reply