This is a screenshot showing the camera position. I want it to rotate slowly smooth to the left and once looking at the soldier to stop rotating.
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
public class SoldierNaviFight : MonoBehaviour
{
public Camera fightCam;
public Transform target;
public float speed = 2f;
// Use this for initialization
void Start ()
{
}
// Update is called once per frame
void Update ()
{
}
}
The script is attached to a empty gameobject. What I want to do is once the camera stopped rotating and looking at the soldier to make the soldier start moving to the right and camera should follow the soldier rotating and keep follow the soldier moving.
The main idea is to create a cut scene. The camera is position at this point just to display the cut scene.
To make the first rotation to the target I tried this:
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
public class SoldierNaviFight : MonoBehaviour
{
public Camera fightCam;
public Transform target;
public float speed = 2f;
Quaternion targetRotation;
// Use this for initialization
void Start ()
{
targetRotation = target.rotation;
}
// Update is called once per frame
void Update ()
{
Quaternion.RotateTowards(transform.rotation, targetRotation, Time.deltaTime * speed);
}
}
But the camera is not rotating at all.
This is screenshot of the Hierarchy and Inspector:
The script is attached to GameObject: SoldierNaviFight The camera that I want to move is the child of SoldierNaviFight: SoldierNaviFightCamera
UPDATE:
This will rotate the camera but it's rotating it to the right instead to the left to the soldier. Not sure why:
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
public class SoldierNaviFight : MonoBehaviour
{
public Camera fightCam;
public Transform target;
public float speed = 2f;
Quaternion targetRotation;
// Use this for initialization
void Start ()
{
targetRotation = target.rotation;
}
// Update is called once per frame
void Update ()
{
fightCam.transform.rotation = Quaternion.RotateTowards(fightCam.transform.rotation, targetRotation, Time.deltaTime * speed);
}
}