Another Smooth Camera Follow problem
I know this is asked a lot but I've been through a ton of these threads and still cannot seem to get my camera nice and smooth. I've tried various methods.
As of now here are my codes..
My player movement is as follows (you can only move left and right):
void FixedUpdate ()
{
float moveHorizontal = Input.GetAxis ("Horizontal");
Vector3 movement = new Vector3 (moveHorizontal, 0.0f, 0.0f);
rb.AddForce (movement * speed);
}
This is my favorite type of camera movement (as far as how I want it to work goes), but is super choppy, mostly when the player is going far right or far left (like holding down left or right so the player is on the edge):
void LateUpdate () {
Vector3 velocity = Vector3.zero;
transform.position = Vector3.SmoothDamp(transform.position, GameObject.Find("Player").transform.position + offset, ref velocity, 0.03f);
transform.rotation = Quaternion.Euler(0f,0f, (velocity.x/-10));
}
This one seems to be a bit smoother but is STILL not perfectly smooth (and doesn't have the nice x rotation but I haven't written it yet) - the problem still arises when the player is going hard left/right:
void LateUpdate () {
transform.position = Vector3.Lerp(transform.position, GameObject.Find("Player").transform.position + offset, 20f * Time.deltaTime);
}
My player is set to Interpolate, I tried setting my application to 60fps, I've tried many of the scripts I've found and I just cannot get a perfectly smooth camera. It always gets choppy when the player is moving hard left or right (when the player is on the edge and can no longer move right within the field of view) while the camera follows.
I've put the camera as a child of the player with no script attached and it is perfectly smooth so I don't believe the problem to be the player movement.
Any help would seriously be great! I'm a little frustrated I can't figure this out but it seems other people have their scripts mostly fixed when they put the camera script in LateUpdate.
Thanks so much for reading! I know this is probably annoying to have yet ANOTHER smooth camera follow question so I do apologize for that!
Answer by Magius96 · Mar 07, 2016 at 04:19 PM
I would suggest using something like iTween on your camera movements. If used right, it can help smooth the camera movement out.
http://www.itween.pixelplacement.com/index.php
Don't let the "animation" word scare you, because what you are trying to do is in effect animating the camera position.
Thank you so much for the reply! I will absolutely try this out! This camera has been bugging me and I just can never seem to get it nice and smooth so I hope this helps. Looks like it could come in handy for a bunch of different things, though!
So I'm definitely doing something wrong. I have this in my LateUpdate on my camera script: iTween.$$anonymous$$oveBy(cam, iTween.Hash("x", GameObject.Find ("Player").transform.position + offset, "easeType", "easeInOutExpo", "loopType", "pingPong", "delay", .1)); where "cam" is the $$anonymous$$ain Camera, but I am getting an error "Cannot cast from source type to destination type.
I'm a little confused by their sample. Sorry, I am pretty new to C# and Unity so I don't think I fully understand how this iTween works yet.