Player to Face NPC

Announcements, support questions, and discussion for the Dialogue System.
Post Reply
c166
Posts: 38
Joined: Fri Oct 14, 2022 11:08 pm

Player to Face NPC

Post by c166 »

Hey Tony,

I want to make the player and NPC face each other when the conversation starts. I know about the Sequencer (LookAt(listener, speaker, 1); ), and I thought that by placing them in the default sequence/ player sequence that I'd be able to achieve this behavior.
default_sequences.PNG
default_sequences.PNG (23.96 KiB) Viewed 19 times
This worked in the Dialogue Demo Scene, but when I play it in my own scene. Only the NPC rotates to face the player. I am not sure if there is something obvious I am missing? (e.g. a component that needed to be assigned?)

Best Regards,
C
User avatar
Tony Li
Posts: 21634
Joined: Thu Jul 18, 2013 1:27 pm

Re: Player to Face NPC

Post by Tony Li »

Hi,

Make sure player and NPC GameObjects are being used as the speaker and listener. Please see Character GameObject Assignments.

I recommend moving the LookAt() command to the first dialogue entry node in the conversation. This way you won't get unexpected side effects if you involve an additional character in a later node in some conversation.

If you want to have both characters change their rotations immediately to face each other, rather than rotating gradually over 1 second, you can use "LookAt()" without any parameters.
c166
Posts: 38
Joined: Fri Oct 14, 2022 11:08 pm

Re: Player to Face NPC

Post by c166 »

Hey Tony,

Thanks for that, I checked and those have been set up correctly - but thanks to ruling out me missing something basic on the Dialogue system side, I realized that the reason is because my player character is using a kinematic controller which can't have the rotation directly modified.

I ended up creating a custom look at sequencer - which is exactly the same as the PixelCrusher LookAt, except with a call to a function if the subject is the player to provide those update references via the KinematicController. Now everything works as expected (both characters turn to look at one another on conversation start)

Code: Select all

            // If the subject to rotate is the player
            if(subject.GetComponent<PlayerController>()!=null)
            {
                Debug.Log("Custom Look At To trigger player look at object");
                subject.GetComponent<PlayerController>().PlayerLookAtObject(target.gameObject);
            }
So now I'll be able to trigger the mutual LookAt using the via the dialogue notes/ sequencer workflow - which makes it much easier to handle. I was setting calls to those functions in "OnConversationStart" via the Dialogue System Trigger previously (before I found out about the Sequencer functionality); which was hard to keep track of.

Best Regards,
C
Post Reply