- Home /
How can i make the camera to travel between all the cubes childs smooth ?
The camera should be at height 0 now the camera position is at 0,0,0 What i want is that the camera to travel between all the children cubes and in the end to move up.
The part that the camera move up smooth i did already:
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
public class CameraMove : MonoBehaviour {
public float smoothSpeed = 3f;
// Use this for initialization
void Start () {
}
// Update is called once per frame
void Update () {
}
private void FixedUpdate()
{
transform.position = Vector3.Lerp(transform.position, new Vector3(0, 500, 0), smoothSpeed * Time.deltaTime);
}
}
But first i want the camera to travel between the whole children cubes. The camera should facing to the cubes and rotate smooth where it need.
This is a screenshot showing the point of view i want the camera to travel and to rotate according to the cubes position to be facing all the time to the cubes. There are many cubes that make the word: "Hello World" and i want to travel inside the Hello World cubes.
I tried this now but it's not working like i wanted at all. It's moving but not as i wanted without turning when needed.
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
public class Camera$$anonymous$$ove : $$anonymous$$onoBehaviour {
public float smoothSpeed = 0.3f;
public GameObject childs;
private Transform[] allChildren;
// Use this for initialization
void Start ()
{
allChildren = childs.GetComponentsInChildren<Transform>();
StartCoroutine(moving());
}
// Update is called once per frame
void Update ()
{
}
IEnumerator moving()
{
foreach (Transform child in allChildren)
{
transform.position = Vector3.Lerp(transform.position, new Vector3(child.position.x, 0, child.position.z), smoothSpeed * Time.deltaTime);
yield return new WaitForSeconds(0);
}
}
private void FixedUpdate()
{
}
}
This is what i got so far. Still not good enough. $$anonymous$$aybe i should not move between all the children cubes ? How can i make it will move only between some of the cubes but still look realistic ?
And still the rotation is not good enough not like i wanted.
Another problem i notice when the camera is moving at some point the camera start going down. Not sure why.
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
public class Camera$$anonymous$$ove : $$anonymous$$onoBehaviour {
public float smoothSpeed = 3f;
public float cameraRotationSpeed = 0.1F;
public GameObject childs;
private Transform[] allChildren;
// Use this for initialization
void Start ()
{
allChildren = childs.GetComponentsInChildren<Transform>();
StartCoroutine(moving());
}
// Update is called once per frame
void Update ()
{
}
IEnumerator moving()
{
foreach (Transform child in allChildren)
{
transform.position = Vector3.Lerp(transform.position, new Vector3(child.position.x, 0, child.position.z), smoothSpeed * Time.deltaTime);
transform.rotation = Quaternion.Slerp(transform.rotation, child.rotation, Time.time * cameraRotationSpeed);
yield return new WaitForSeconds(0);
}
}
private void FixedUpdate()
{
}
}
Answer by Cuttlas-U · Oct 04, 2017 at 04:18 AM
hi; i can help u if u want install team viewer and send me a gmail so i help u : savajjad@gmail.com
Your answer
Follow this Question
Related Questions
How can i prevent from mouse to collide with thirdpersoncontroller ? 0 Answers
How can i change the walls height and keep the size for example 100x100 but height 0.1 ? 1 Answer
How can i using a break point if a gameobject have a collider after added to it ? 1 Answer
How can i get all childs from List ? 3 Answers
How can i set the same script on two GameObjects so the script will work on both objects same time ? 1 Answer