- Home /
following camara issue
Hello guys,
I started with Unity development some weeks ago and still learning a lot, but I'm facing a very strange issue involving a following camera.
I'm using scripts taken from the standard assets Unity provides, but the camara is not smooth when the object is moving fast (rigidbody.velocity > 60).
I uploaded a youtube video to show this odd issue. In the top side of the video you'll see a static camera showing that the object movement is smooth, and in the bottom side you'll see the following camera (it's a 2D following camera). Note that when the object goes fast, it starts to glitch.
EDIT: Sorry I forgot to add the video link: http://www.youtube.com/watch?v=IMH12OHPS9U
This is the JS code used for the camara (SmoothFollow2D):
var target : Transform; var smoothTime = 0.3; private var thisTransform : Transform; private var velocity : Vector2;
function Start() { thisTransform = transform; }
function LateUpdate() { thisTransform.position.x = Mathf.SmoothDamp( thisTransform.position.x, target.position.x, velocity.x, smoothTime); thisTransform.position.y = Mathf.SmoothDamp( thisTransform.position.y, target.position.y, velocity.y, smoothTime); }
The target is set to a gameobject containing all the objects used for hte UFO.
What could be happening?
Thanks in advance for your help, Juan.
Answer by AngryOldMan · Mar 18, 2011 at 05:06 PM
parent the camera to the object manually in the hierarchy. Don't attach the script.
hmm sorry I don't understand, how do I parent the camera to the gameobject? Please consider tha what I try to achieve is some smooth camera but with a little delay on the movement.
Ah i see. You don't want to parent the camera you want to change function LateUpdate to function Update and see if that serves you any better. Also add a definable background so you can understand if it's the game that is glitchy/dropping frames or if it's just the way your camera is acting. Then try altering your variables (or atleast watching them through a different variable for the private var velocity)
Juancito, it is common for "camera follow" scripts to be run in LateUpdate. It guarantees that the camera will update its status after all other objects have moved. Is there a specific reason you suggest moving it into Update?
Juancito's other suggestion is a good one. I found it hard to interpret the camera movement in the video without a background for reference.
if you look that's my other suggestion. Fair play with the LateUpdate function though was just a suggestion if it was the game dropping frames, in order to keep the camera updating along with everything else!
Your answer
Follow this Question
Related Questions
Help with a 2d camera Controller 1 Answer
Issues with player prefabs when I try to teleport it 1 Answer
Main Camera child under player, causes flip 3 Answers
Many cameras with Camera.main.ScreenToWorldPoint trouble. 2 Answers
Camera wrapping 0 Answers