It's there any way of lerping the camera position by inputting a button? I have a code that changes the camera pos but I want it to be smooth and I don't know how to make this. This is the code: Code (CSharp): using System.Collections; using System.Collections.Generic; using UnityEngine; public class ChangeCamera : MonoBehaviour { public GameObject thirdPCamPos; //emptyObj public GameObject firstPCamPos; //emptyObj public GameObject cam; public string ChangeCam; //InputKey public bool is3P; //is third person void Update() { if(Input.GetButtonDown (ChangeCam)) { if(is3P == true) { InvokeRepeating("CamToFirst", 0f, 0f); } if(is3P == false) { InvokeRepeating("CamToThird", 0f, 0f); } is3P = !is3P; } } } thanks in advance.
I am a noob here, but how about you translate the position and rotation of your Camera to where you want it to go (Like an empty game object), and just add Lerp/Slerp to it. Instead of switching between 2 cameras. Noob here though so maybe I dont know what I am talking about lol
I'm not switching, I am changing the camera position to the emptys, as I said in the //, but I don't know how to lerp because I want it to change every time you tab the ChangeKey
Code (CSharp): using UnityEngine; using System.Collections; public class ExampleClass : MonoBehaviour { // Transforms to act as start and end markers for the journey. public Transform startMarker; public Transform endMarker; // Movement speed in units per second. public float speed = 1.0F; // Time when the movement started. private float startTime; // Total distance between the markers. private float journeyLength; void Start() { // Keep a note of the time the movement started. startTime = Time.time; // Calculate the journey length. journeyLength = Vector3.Distance(startMarker.position, endMarker.position); } // Move to the target end position. void Update() { // Distance moved equals elapsed time times speed.. float distCovered = (Time.time - startTime) * speed; // Fraction of journey completed equals current distance divided by total distance. float fractionOfJourney = distCovered / journeyLength; // Set our position as a fraction of the distance between the markers. transform.position = Vector3.Lerp(startMarker.position, endMarker.position, fractionOfJourney); } }
Doesn't work, the camera does not go smoothly and it stops in the way to the position it should be because its a GetButtonDown input.
add "time.Deltatime" to these functions "CamToFirst". Sorry if I am not Much Help, Btw, might Also be Possible Using Animations
I only Started 2 weeks ago Despite how old my account is, and I have been stuck with every step of the way, but I must say, that every time I get stuck I learn so much.. I am actually stuck right now as we speak!
@Giovane, Your Welcome Bro, Btw I only come to the forum to ask for help if I cant find the Answer on youtube and in the Scripting reference first. I think if you do the same it may save you time