- Home /
Smooth transition between Camera FOV and GameObject
Hello friends,,, I am a beginner in unity, I am making a 3d game in which I want the field of view of camera increase smoothly with the increase in speed of my moving game object (currently a cube) & vice versa. I am using transform.translate to move my cube for now, but it doesn't seem to work for me till now to even accelerate and to change FOV either. But I would say that I have tried Mathf and Vector.Lerp too for doing what I want but I didn't get the results. Any help would be appreciated. Thanks in advance.
Lerp, translate and all are pretty straight forward. "Trying" doesn't sound like well thought out. Think the whole problem through, then code it. Lerp is definitely possible, it just depends on how you implement it.
Answer by Davinder_Singh · Jun 13, 2017 at 04:11 AM
@JeffHardddyyy I think, I didn't asked question properly... But still, looking at your this script, I have got idea for my game's script and the problem is half solved. Now the only problem remaining is of how to accelerate and de-accelerate my game object. Problem of FOV is solved. ;)
Thanks for that.
Answer by JeffHardddyyy · Jun 11, 2017 at 11:45 PM
Hopefully this works! Sorry you had to wait 24 hours to answer, Lol!
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
public class myScript : MonoBehaviour
{
public Camera myCam; //the camera
public int amount; //how many times do you want it to
void Start()
{
for (int i = 0; i < amount; i++)
{
myCam.fieldOfView++;
}
}
}
Or: using System.Collections; using System.Collections.Generic; using UnityEngine;
public class myScript : $$anonymous$$onoBehaviour
{
public Camera myCam; //the camera
public float Seconds; //how many seconds until it zooms out?
public int How$$anonymous$$uch; //how much should it ZoomOut
void Start()
{//on start
StartCoroutine("ZoomCamera"); //start "ZoomCamera"
}
IEnumerator ZoomCamera()
{//when called
yield return new WaitForSeconds(Seconds); //wait [Seconds] Seconds
myCam.fieldOfView += How$$anonymous$$uch; //add [How$$anonymous$$uch] to the field of view
StartCoroutine("ZoomCamera");//loop
}
}
Your answer
Follow this Question
Related Questions
Dark Souls like camera going through walls, please help 0 Answers
Limiting vertical camera rotation 0 Answers
Why is the camera going crazy when the player moves? 0 Answers
Multiple Cars not working 1 Answer
Change from 3D to 2D 1 Answer