- Home /
Setting the FPS Camera to a certain position
Hello! So I am trying to make my player's FPS camera face a certain target after entering the room, and become locked in place while an NPC says about five seconds worth of dialogue. After the dialogue ends, I would like the character to become unfrozen, but will continue facing the enemy right after the restraints are gone, just to add consistency. Right now, after the character looks at the NPC for the dialogue and the restraints come off, the FPS camera snaps off to the left, and the player has to turn back to the enemy to see it. Here is my code below-
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using UnityEngine.SceneManagement;
using UnityStandardAssets.Characters.FirstPerson;
public class FPSplacement : MonoBehaviour {
private GUIruntime2 guiruntime2;
public GameObject FPSController;
public Transform target;
public GameObject spawn;
private FirstPersonController disabled;
public Camera cam;
// Use this for initialization
void Start () {
Scene currentscene = SceneManager.GetActiveScene();
string sceneName = currentscene.name;
guiruntime2 = FPSController.GetComponent<GUIruntime2>();
disabled = FPSController.GetComponent<FirstPersonController>();
}
// Update is called once per frame
void Update () {
if (SceneManager.GetActiveScene() == SceneManager.GetSceneByName("SimpleSword2part2") && guiruntime2.roar == true)
{
StartCoroutine(Waiting());
}
}
IEnumerator Waiting()
{
//spawn is the position the FPS controller will spawn into when the scene changes
transform.position = spawn.transform.position;
transform.LookAt(target);
//disabled holds the FPS script, and disables it so the player can't move
disabled.enabled = false;
yield return new WaitForSeconds(5);
//reneables the FPS script
//disabled guiruntime2.roar, which is calling a bool from the script for the actual dialogue
disabled.enabled = true;
guiruntime2.roar = false;
}
}
I have tried using transform.LookAt, but that forces the player to lock onto the enemy, and they aren't able to look around unless they move the camera erratically, which for some reason breaks the transform.LookAt.
Your answer

Follow this Question
Related Questions
Need help for a Card Game! How to place the cards at the right spot? 0 Answers
setParent either shrinks my child object or blows it up... What gives? 3 Answers
Camera Rotation on Touch. Clamp rotation. 2 Answers
Visual Studios says that script doenst exist but it does. 1 Answer
Confining Mouse Look on X axis 0 Answers