- Home /
Why does my Mathf.SmoothDamp work for the Camera?
Could somebody explain to me why this code works? I don't understand why i need to ref a velocity vector.
public GameObject player;
public float smoothMultiplier;
private Transform tr;
private Vector3 camDistance;
private Vector2 velocityRef;
void Awake ()
{
tr = transform;
}
void Start ()
{
camDistance = transform.position;
}
void Update ()
{
}
void LateUpdate ()
{
float newPositionx = Mathf.SmoothDamp(tr.position.x, player.transform.position.x, ref velocityRef.x, smoothMultiplier);
float newPositiony = Mathf.SmoothDamp(tr.position.y, player.transform.position.y, ref velocityRef.y, smoothMultiplier);
tr.position = new Vector3 (newPositionx,newPositiony,camDistance.z);
}
}
Vector2 velocityRef has a value of Vector2.zero right? Then why does my camera script work? Do I just have a crap understanding of C#? I thought when you reference something, that something needs to have a value assigned to it right?
I've read this article trying to explain this to me, but I understood only the first half of it and got super confused at the end. Ultimately I still have no idea why SmoothDamp wants a ref to an empty vector.
Comment
Your answer
![](https://koobas.hobune.stream/wayback/20220613141527im_/https://answers.unity.com/themes/thub/images/avi.jpg)
Follow this Question
Related Questions
Distribute terrain in zones 3 Answers
Multiple Cars not working 1 Answer
Full screen camera missing? 3 Answers
how do i make first person character rotate left and right along with camera? 0 Answers