- Home /
Shaky player effect when I apply a damping camera follow script?
I stumbled across this script on Unity answers, and I decided to stick it on rather than just make the camera a child object of the player. It works perfectly, except when the player is moving it makes the player look like it's shaking. I think the term for that is "clipping" or something like that. Anyway, on the script, when I change the damping variable to 0, the player doesn't shake anymore, so it has to do with the damping. But I want the damping. Is there anyway to have the damping but not have the player appear to be shaking? Here's the script:
using UnityEngine;
using System.Collections;
public class CameraFollowFoReal : MonoBehaviour {
public float dampTime = 0.15f;
private Vector3 velocity = Vector3.zero;
public Transform target;
// Update is called once per frame
void Update ()
{
if (target)
{
Vector3 point = camera.WorldToViewportPoint(target.position);
Vector3 delta = target.position - camera.ViewportToWorldPoint(new Vector3(0.5f, 0.5f, 20f)); //(new Vector3(0.5, 0.5, point.z));
Vector3 destination = transform.position + delta;
transform.position = Vector3.SmoothDamp(transform.position, destination, ref velocity, dampTime);
}
}
}
Any ideas what's wrong with it? I think from reading online it has something to do with clamping, but I can't seem to figure it out. Any help is much appreciated.
Edit: I should probably add, my game is 2D. Here is a screenshot of it so you can visualize what I mean:
Nothing else shakes when the camera moves, the tree and ground look normal, it's just the player.
I think it would be legit to put a comment on the original answer. If they're still here, they'll see the Q is "Active" when they log back in.
But, with "For" misspelled in the name, and a dead var -- point -- down below, and not using Time.deltaTime, I'm tempted to say this may never have worked correctly.
And, clipping, used negatively, means something that should be there is "clipped off." Like if your head blinked out whenever you walked in front of the tree. So your problem isn't clipping.
Answer by Dead Lincs · Feb 17, 2014 at 03:15 PM
If you have Unity 4.3.4f1 or above you can download the new Sample Assets beta test package free from the asset store which contains the new first person player system with advanced head bobbing and tilting and a smooth mouse look script as well as a head pivot and running all built in :D I find it useful the only thing it doesn't do is crouch but you could add that yourself :)
This is really useful to know, thank you. But this camera is actually for a 2D game, so the First Person script wouldn't really help in this case :P Thanks anyway though.
It does also contain a 2D platformer with a player too :)