How to make my camera follow the ball smoothly, because when the players touch the camera is not really stable
using UnityEngine; using System.Collections;
public class Camera_Script : MonoBehaviour {
private bool isTriggering = false;
private float distanceAdder = 0.0f;
private float distanceAdder2 = 0.0f;
private bool isExit = false;
public Transform target;
public Vector3 targetOffsetPos;
private Vector3 oldPos;
// Use this for initialization
void Start () {
}
// Update is called once per frame
void LateUpdate () {
if ( GetComponent<InGameState_Script>().state == InGameState_Script.InGameState.PLAYING
|| GetComponent<InGameState_Script>().state == InGameState_Script.InGameState.Run
|| GetComponent<InGameState_Script>().state == InGameState_Script.InGameState.Remove) {
oldPos = transform.position;
Vector3 newPos = new Vector3( target.position.x+targetOffsetPos.x, target.position.y+targetOffsetPos.y, target.position.z+targetOffsetPos.z );
float lerpX = Mathf.Lerp( oldPos.x, newPos.x, 0.05f );
float lerpY = Mathf.Lerp( oldPos.y, newPos.y, 0.05f );
float lerpZ = Mathf.Lerp( oldPos.z, newPos.z, 0.05f );
transform.position = new Vector3( lerpX, lerpY, lerpZ ); transform.LookAt( target );
}
if ( GetComponent<InGameState_Script>().state == InGameState_Script.InGameState.CORNER_1
|| GetComponent<InGameState_Script>().state == InGameState_Script.InGameState.CORNER) {
GameObject lanzador = GetComponent<InGameState_Script>().candidateToKick;
if ( lanzador ) {
transform.position = lanzador.transform.position - lanzador.transform.forward*15.0f + lanzador.transform.up*3.0f ;
transform.LookAt( target );
}
}
}
}
Hi.
This is not a scripting service. Posting your whole script without explaining anything in detail in the question body is not appropriate on UA. Your Question title should be short and descriptive.
when the players touch the camera is not really stable
..what is this supposed to mean?
How to make my camera follow the ball smoothly
..there are many many tutorials for this. Check Google, Forums or Youtube for tutorials. Not UA. Check the FAQ to the top right of the page for information about how to use UA.
Have a nice day, everyone starts as a beginner somewhere. ;)
Answer by Orthrinicus · Mar 08, 2016 at 09:54 PM
@shpetim_91 this link may help with what you are trying to do, it basically just shows you a script that smoothly follows an object in the scene:
https://unity3d.com/learn/tutorials/projects/survival-shooter/camera-setup?playlist=17144
it starts at around 2:00 till the end
enjoy