Hi there,
I've been using the LookAt() function quite a bit in my game. However, my problem right now is that I want my player character to look up at something in the distance. Whenever I call this with the LookAt() function, the camera barely rotates, even with allAxes enabled. Is there a way I can have my character look higher up or perhaps focus on something in the distance?
Make LookAt() Function look up?
-
- Posts: 65
- Joined: Fri Feb 06, 2015 3:51 pm
Re: Make LookAt() Function look up?
Also, somewhat related, but the opposite problem: How do I force the camera to look straight. I've noticed that if my player happens to be looking up or down or in certain weird ways when they enter a trigger that starts a cutscene and the lookAt function is called, it will rotate the camera, but only on the horizontal axis. For example, if they enter a cutscene trigger and and they're currently looking up for whatever reason, they will keep looking up and when the LookAt function is called, it will rotate the camera in the direction of the target, but they will still be looking up.
How do I fix that?
How do I fix that?
Re: Make LookAt() Function look up?
Hi,
The answer may depend on non-Dialogue System stuff like the player controller that you're using (e.g,. Unity's FirstPersonController). The FirstPersonController may be taking control of the camera's vertical rotation. Also, when you use LookAt() with allAxes, it will rotate the FirstPersonController so it's no longer upright. This leaves it in a messed up state after conversations.
To bypass all those non-Dialogue System concerns, consider using a dedicated sequencer camera. To do this, follow these steps:
1. Add a new camera to the scene (GameObject > Camera). Name it "Sequencer Camera" and deactivate it (the GameObject, not the Camera component). (You can also make it a prefab and assign the prefab directly from your Project view.)
2. Assign it to the Dialogue Manager's Camera Settings > Sequencer Camera field.
When conversations start, the Dialogue System will temporarily disable the main player camera. It will then make a clone of Sequencer Camera. Camera() commands will use it instead of the main player camera.
To match the player camera at the start of the conversation, use the Camera() command:
where <yourMainPlayerCameraName> is the name of your main player camera.
Another nice thing about using a dedicated sequencer camera is that you can put special post-processing components on it, such as Depth Of Field to focus on the NPC and blur the background.
If you want to continue to use the main player camera, let me know. We can get that working, too.
The answer may depend on non-Dialogue System stuff like the player controller that you're using (e.g,. Unity's FirstPersonController). The FirstPersonController may be taking control of the camera's vertical rotation. Also, when you use LookAt() with allAxes, it will rotate the FirstPersonController so it's no longer upright. This leaves it in a messed up state after conversations.
To bypass all those non-Dialogue System concerns, consider using a dedicated sequencer camera. To do this, follow these steps:
1. Add a new camera to the scene (GameObject > Camera). Name it "Sequencer Camera" and deactivate it (the GameObject, not the Camera component). (You can also make it a prefab and assign the prefab directly from your Project view.)
2. Assign it to the Dialogue Manager's Camera Settings > Sequencer Camera field.
When conversations start, the Dialogue System will temporarily disable the main player camera. It will then make a clone of Sequencer Camera. Camera() commands will use it instead of the main player camera.
To match the player camera at the start of the conversation, use the Camera() command:
Code: Select all
Camera(<yourMainPlayerCameraName>, NPC)
Another nice thing about using a dedicated sequencer camera is that you can put special post-processing components on it, such as Depth Of Field to focus on the NPC and blur the background.
If you want to continue to use the main player camera, let me know. We can get that working, too.
-
- Posts: 65
- Joined: Fri Feb 06, 2015 3:51 pm
Re: Make LookAt() Function look up?
If the seqencer camera is my only/best option okay. However, if possible, can we try to get this working on the First Person Controller's Camera? I'm pretty far into development now and have many sequence calls written so I'd like to avoid the hassle of adding another element that could potentially cause an issue and/or rewriting a lot of sequence commands. I haven't used the Sequencer Camera yet and don't want to risk spending too much time on something I'm not familiar with at this point.
Re: Make LookAt() Function look up?
Here's an example scene with the Unity standard First Person Controller prefab. It's built in Unity 5.1.0.
LookAtTest_2015-07-21.unitypackage
The conversation is between the player and Private Hart. The First Person Controller has a child GameObject named "FirstPersonCharacter". This GameObject has the camera and is the GameObject that you want to control with LookAt().
Private Hart's first node has this Sequence, which simply makes both participants look at each other.
The second node has this Sequence, which makes the player look at a GameObject named "Moon" that's on the ceiling:
LookAtTest_2015-07-21.unitypackage
The conversation is between the player and Private Hart. The First Person Controller has a child GameObject named "FirstPersonCharacter". This GameObject has the camera and is the GameObject that you want to control with LookAt().
Private Hart's first node has this Sequence, which simply makes both participants look at each other.
Code: Select all
LookAt(FPSController);
LookAt(Private Hart Head, FirstPersonCharacter,0.5,allAxes)
Code: Select all
LookAt(Moon,FirstPersonCharacter,2,allAxes)
-
- Posts: 65
- Joined: Fri Feb 06, 2015 3:51 pm
Re: Make LookAt() Function look up?
Alright, that seems to work much better. Now I just need to find everywhere that I have Player in LookAt and change it.
The only issue left with this though is that after the duration, it seems that unless I have a conversation triggered, it will revert back to its old rotation. For example, I was testing this with another scene I was already working on where a sequence begins on trigger enter that makes the player look at something, wait a moment, then look at a character and begin conversation. To test using FirstPersonCharacter, I had the character look up while approaching the trigger. The moment where it waited had the rotation move back up. Is there a way to make it hold looking at the object in the moment it waits?
The only issue left with this though is that after the duration, it seems that unless I have a conversation triggered, it will revert back to its old rotation. For example, I was testing this with another scene I was already working on where a sequence begins on trigger enter that makes the player look at something, wait a moment, then look at a character and begin conversation. To test using FirstPersonCharacter, I had the character look up while approaching the trigger. The moment where it waited had the rotation move back up. Is there a way to make it hold looking at the object in the moment it waits?
Re: Make LookAt() Function look up?
I bet the FirstPersonController's script is trying to control the camera during the sequence. Disable the script during the sequence using one of these two options:
1. Add a Set Component Enabled On Dialogue Event component. Set the trigger to OnSequence. In the OnStart section, disable the FirstPersonController script. In the OnEnd section, re-enable it. I recommend adding this component to the sequence trigger GameObject. Assign the sequence trigger GameObject to the sequence trigger's "Speaker" field so it'll receive the OnSequenceStart/End messages.
2. Or use the SetEnabled() sequencer command within your sequence:
I'm out of the office at the moment, so I can't verify the names of the First Person Controller GameObject or its FirstPersonController.cs script, but I hope this gets the idea across.
1. Add a Set Component Enabled On Dialogue Event component. Set the trigger to OnSequence. In the OnStart section, disable the FirstPersonController script. In the OnEnd section, re-enable it. I recommend adding this component to the sequence trigger GameObject. Assign the sequence trigger GameObject to the sequence trigger's "Speaker" field so it'll receive the OnSequenceStart/End messages.
2. Or use the SetEnabled() sequencer command within your sequence:
Code: Select all
SetEnabled(FirstPersonController, false, First Person Controller);
LookAt(theMoon, FirstPersonCharacter, 2);
SetEnabled(FirstPersonController, true, First Person Controller)@2