Selector raycast is sliding through collider?

Announcements, support questions, and discussion for the Dialogue System.
Post Reply
gpotatok
Posts: 6
Joined: Thu Aug 10, 2023 1:50 am

Selector raycast is sliding through collider?

Post by gpotatok »

Hi, I am trying to use the dialogue system in my project and I'm having some strange problem.

I have a customer GameObject in my scene, and I'm trying to trigger a conversation when it is clicked.
I set its dialogue system trigger to "On Use", and I set a Selector component to a blank Gameobject, and set "Select At" value to "Mouse Position".

I think I set all settings just as tutorial except it triggers with mouse 0 button, but in my project, use message was sometimes not showing, and I couldn't trigger the conversation. The bigger problem was that this was not happening always.

So I set the debug option in Selector on, and I found that raycast collider from mouse was sliding through the customer object, and once it sled completely out from customer object, I couldn't trigger the conversation anymore.



Could it be a problem of raycast system itself or is there anything I can do to fix this? Thanks.
User avatar
Tony Li
Posts: 22119
Joined: Thu Jul 18, 2013 1:27 pm

Re: Selector raycast is sliding through collider?

Post by Tony Li »

Hi,

Is it possible that the collider on that capsule is shorter than the capsule itself? I'm not sure, but it looks like maybe the mouse is moving very slightly up. Maybe it's eventually raycasting just above the collider. Other than that, I have no idea. Are any scripts manipulating the collider maybe?
gpotatok
Posts: 6
Joined: Thu Aug 10, 2023 1:50 am

Re: Selector raycast is sliding through collider?

Post by gpotatok »

The collider is same size as the capsule itself, and the raycast just stops to collide with capsule after sliding out even if I drag the cursor out and back. I don't have any script that changes the collider either.

It seems that size of raycast collider might be a problem, and I just dealt with it by increasing the size of capsule collider for now.

I'm sorry but I am new to raycast system, so is there a way I can change the size of raycast collider so that I don't have to change all colliders of npc objects when I don't need, or should not?
User avatar
Tony Li
Posts: 22119
Joined: Thu Jul 18, 2013 1:27 pm

Re: Selector raycast is sliding through collider?

Post by Tony Li »

Hi,

I don't know what's happening in your scene. The Selector does a basic raycast from the camera's position along a ray specified by the mouse position. Would it be possible for you to send a reproduction project to tony (at) pixelcrushers.com?
User avatar
Tony Li
Posts: 22119
Joined: Thu Jul 18, 2013 1:27 pm

Re: Selector raycast is sliding through collider?

Post by Tony Li »

Hi,

Thanks for sending the repro project. The selector's raycast isn't sliding through the collider. Your AI script is moving the collider (actually, its rigidbody) so that it's not where the capsule is being rendered. Try changing this code:

Code: Select all

GetComponent<Rigidbody>().position = targetPosition;
GetComponent<Rigidbody>().rotation = Quaternion.identity;
to this:

Code: Select all

transform.SetPositionAndRotation(targetPosition, Quaternion.identity);
gpotatok
Posts: 6
Joined: Thu Aug 10, 2023 1:50 am

Re: Selector raycast is sliding through collider?

Post by gpotatok »

Thank you for your kind help!

The code itself did not straightforward fixed the problem, but just as you pointed out, I found out that the rigidbody of guest object was falling free from rendered mesh. I turned off the gravity of guest object and it solved the issue.

It seems to be happened because Navmesh agent and Rigidbody are independent each other, and I'm still not quite sure why scene window still showed the collider as it was not moving at all... but I guess it was just because of those components getting messed up??

Anyway, thanks again. It would have been impossible to fix it without your help.
User avatar
Tony Li
Posts: 22119
Joined: Thu Jul 18, 2013 1:27 pm

Re: Selector raycast is sliding through collider?

Post by Tony Li »

Glad to help!
Post Reply