1
\$\begingroup\$

I want my camera to be smooth on only the Y axis.How do I do that it?

Current code:

public Transform target;
public float smoothSpeed = 0.3f;
public float offsetX = 1f;
public float offsetY = 1f;
public float offsetZ = 1f;


void FixedUpdate ()
{
    Vector3 pos = transform.position;
    pos.x = target.position.x;
    pos.y = target.position.y;
    pos.z = target.position.z;
    Vector3 positionz = pos.z;

    Vector3 smoothedPosition = Vector3.Lerp(transform.position, pos, smoothSpeed);
    transform.position = smoothedPosition;
}
\$\endgroup\$
1
\$\begingroup\$

Just lerp only the y component.

Don't be afraid to just try stuff like this yourself — it's a lot faster to muck with a few formulas and see what they do than wait for an answer from a stranger. ;)

Vector3 pos = target.position;

pos.y = Mathf.Lerp(transform.position.y, pos.y, sharpness);

transform.position = pos;

Note that to get consistent behaviour under varying framerates, you'll need to adjust the sharpness parameter as explained here.

\$\endgroup\$

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.