NPC Look at Player

Announcements, support questions, and discussion for the Dialogue System.
nitrox32
Posts: 68
Joined: Sat Dec 01, 2018 10:41 am

NPC Look at Player

Post by nitrox32 »

I'm using DS and UCC together and I have managed to get my player and NPC to interact using OnTriggerEnter to start the conversation and pause the game while conversing. I would like the NPC to face me. This seems simple to do but I can't find any info on how to do it. Can you point me in the right direction?
nitrox32
Posts: 68
Joined: Sat Dec 01, 2018 10:41 am

Re: NPC Look at Player

Post by nitrox32 »

OK, I figured out that I can do a sequence "Camera(Closeup, listener, 1)" that does what I want however the player is in the background of my NPC. This only happens when I approach the NPC from the back. The player is a UCC first person character.
User avatar
Tony Li
Posts: 20642
Joined: Thu Jul 18, 2013 1:27 pm

Re: NPC Look at Player

Post by Tony Li »

Hi,

The Dialogue System has an Opsive UCC integration package. You can use UCC's Interact ability to start a conversation if you want, or continue to use OnTriggerEnter, or mix and match in different situations.

In addition to the Camera() sequencer command, you can also use the LookAt() sequencer command to rotate GameObjects (such as the NPC) to face other GameObjects. For example, the sequence below will rotate the NPC to face the player and then move the camera into a closeup of the NPC. It assumes that it's on a dialogue entry node that's spoken by the NPC (i.e., a gray node).

Code: Select all

LookAt(listener);
Camera(Closeup, speaker, 1)
The first line tells the speaker (the NPC) to face the listener (player). The second line does a closeup of the speaker (NPC) over 1 second.

If you're editing the Sequence field for a player node (i.e., blue), it would be:

Code: Select all

LookAt(speaker,listener);
Camera(Closeup,listener,1)
The first line tells the listener (NPC) to face the speaker (player). The second line does a closeup of the listener (NPC).
nitrox32
Posts: 68
Joined: Sat Dec 01, 2018 10:41 am

Re: NPC Look at Player

Post by nitrox32 »

Thanks for getting back to me so quickly. Perhaps I am entering something incorrectly but I still have my player shown in the background.
Capture2.JPG
Capture2.JPG (52.66 KiB) Viewed 1550 times
Capture.JPG
Capture.JPG (89.43 KiB) Viewed 1550 times
User avatar
Tony Li
Posts: 20642
Joined: Thu Jul 18, 2013 1:27 pm

Re: NPC Look at Player

Post by Tony Li »

Try changing that node's Sequence to:

Code: Select all

LookAt(listener); Camera(Closeup,speaker,1)
This will make the Archer face the player. Your current sequence makes the player face the Archer.

If the Archer is facing the player before the closeup, then the player will not be in the background.
nitrox32
Posts: 68
Joined: Sat Dec 01, 2018 10:41 am

Re: NPC Look at Player

Post by nitrox32 »

Hmmm.....I copied and pasted your sequence. I no longer have my player in view but the NPC doesn't fully look at the player. The camera closes in on the NPC but the NPC doesn't rotate to face the player.
Capture.JPG
Capture.JPG (101.23 KiB) Viewed 1540 times
Capture2.JPG
Capture2.JPG (92.85 KiB) Viewed 1540 times
Attachments
Capture2.JPG
Capture2.JPG (92.85 KiB) Viewed 1541 times
User avatar
Tony Li
Posts: 20642
Joined: Thu Jul 18, 2013 1:27 pm

Re: NPC Look at Player

Post by Tony Li »

Hi,

Would it be possible for you to send an example scene and dialogue database to tony (at) pixelcrushers.com? You can export them as a unitypackage and attach them to an email.

I'm not sure how to reproduce the issue. As a test, I took the Opsive UCC Support's "Opsive UCC Dialogue Example" scene and changed the Sequence of the first node of the Private Hart conversation ("We need to intercept the...") to:

Code: Select all

LookAt(listener); Camera(Closeup,speaker,1)
When I played the scene and interacted with Private Hart, he turned to face the player, and then it did a closeup.

You could also try this:

Code: Select all

LookAt(MainCamera); Camera(Closeup,speaker,1)
This will make your NPC look at the camera instead of the player GameObject, in case they're not lined up for some reason.
nitrox32
Posts: 68
Joined: Sat Dec 01, 2018 10:41 am

Re: NPC Look at Player

Post by nitrox32 »

I just tried the new Sequence you suggested: LookAt(MainCamera); Camera(Closeup,speaker,1). I still notice the same behavior except I am getting this warning:

Dialogue System: Sequencer: LookAt() command: target is null.
UnityEngine.Debug:LogWarning(Object)
PixelCrushers.DialogueSystem.Sequencer:TryHandleLookAtInternally(String, String[]) (at Assets/Plugins/Pixel Crushers/Dialogue System/Scripts/MVC/Sequencer/Sequencer.cs:1518)
PixelCrushers.DialogueSystem.Sequencer:HandleCommandInternally(String, String[], Single&) (at Assets/Plugins/Pixel Crushers/Dialogue System/Scripts/MVC/Sequencer/Sequencer.cs:927)
PixelCrushers.DialogueSystem.Sequencer:ActivateCommand(String, String, Transform, Transform, String[]) (at Assets/Plugins/Pixel Crushers/Dialogue System/Scripts/MVC/Sequencer/Sequencer.cs:674)
PixelCrushers.DialogueSystem.Sequencer:PlayCommand(QueuedSequencerCommand, String, Boolean, Single, String, String, String[]) (at Assets/Plugins/Pixel Crushers/Dialogue System/Scripts/MVC/Sequencer/Sequencer.cs:644)
PixelCrushers.DialogueSystem.Sequencer:PlayCommand(QueuedSequencerCommand) (at Assets/Plugins/Pixel Crushers/Dialogue System/Scripts/MVC/Sequencer/Sequencer.cs:613)
PixelCrushers.DialogueSystem.Sequencer:PlaySequence(String) (at Assets/Plugins/Pixel Crushers/Dialogue System/Scripts/MVC/Sequencer/Sequencer.cs:547)
PixelCrushers.DialogueSystem.Sequencer:PlaySequence(String, Boolean, Boolean) (at Assets/Plugins/Pixel Crushers/Dialogue System/Scripts/MVC/Sequencer/Sequencer.cs:557)
PixelCrushers.DialogueSystem.ConversationView:StartSubtitle(Subtitle, Boolean, Boolean) (at Assets/Plugins/Pixel Crushers/Dialogue System/Scripts/MVC/View/View/ConversationView.cs:160)
PixelCrushers.DialogueSystem.ConversationController:GotoState(ConversationState) (at Assets/Plugins/Pixel Crushers/Dialogue System/Scripts/MVC/Controller/ConversationController.cs:168)
PixelCrushers.DialogueSystem.ConversationController:OnFinishedSubtitle(Object, EventArgs) (at Assets/Plugins/Pixel Crushers/Dialogue System/Scripts/MVC/Controller/ConversationController.cs:224)
PixelCrushers.DialogueSystem.ConversationView:FinishSubtitle() (at Assets/Plugins/Pixel Crushers/Dialogue System/Scripts/MVC/View/View/ConversationView.cs:383)
PixelCrushers.DialogueSystem.ConversationView:OnFinishedSubtitle() (at Assets/Plugins/Pixel Crushers/Dialogue System/Scripts/MVC/View/View/ConversationView.cs:390)
PixelCrushers.DialogueSystem.Sequencer:FinishSequence() (at Assets/Plugins/Pixel Crushers/Dialogue System/Scripts/MVC/Sequencer/Sequencer.cs:475)
PixelCrushers.DialogueSystem.Sequencer:Update() (at Assets/Plugins/Pixel Crushers/Dialogue System/Scripts/MVC/Sequencer/Sequencer.cs:468)
Last edited by nitrox32 on Tue Jun 11, 2019 9:54 pm, edited 1 time in total.
User avatar
Tony Li
Posts: 20642
Joined: Thu Jul 18, 2013 1:27 pm

Re: NPC Look at Player

Post by Tony Li »

In the sequence, change "MainCamera" to the name of your camera GameObject.
nitrox32
Posts: 68
Joined: Sat Dec 01, 2018 10:41 am

Re: NPC Look at Player

Post by nitrox32 »

Opps, I see what you mean. That took care of the warning. Now the Camera is closing in on the NPC but not rotating towards the player. I just realized I was using not using the most recent version of UCC. I was one version behind. I'm going to start over with a fresh project and see if that helps.
Post Reply