Focussing the camera on a mesh?

I want to create a similar game like Flower where the camera follows along a cloth like object in the wind.

I’ve watched many camera tutorials and all of them focus on needing a PlayerTransform to focus the camera on. What i’ve learned is that a cloth system actually alters the mesh itself and not the object. The transform stays in place while the cloth takes off in the wind. Is there any way to make the camera focus on the mesh or the vertices instead of the transform? The code I use right now is:

public class PlayerFollow : MonoBehaviour
{
    public Transform PlayerTransform;

    private Vector3 _cameraOffset;

    [Range(0.01f, 1.0f)]
    public float SmoothFactor = 0.5f;

    // Start is called before the first frame update
    void Start()
    {
        _cameraOffset = transform.position - PlayerTransform.position;   
    }

    // Update is called once per frame
    void LateUpdate()
    {
        Vector3 newPos = PlayerTransform.position + _cameraOffset;

        transform.position = Vector3.Slerp(transform.position, newPos, SmoothFactor);
    }
}

I don’t have a lot of experience with coding so I guess I should change the PlayerTransform.position?

Why do you open a second thread for pretty much the same question you already posted a couple days ago?
I posted a reply there and you did not respond, nor did anybody else, and now you make a new thread. Curious.

I didn’t worked with it myself, but maybe this will lead you into the right direction:
Use Renderer.bounds (This is the axis-aligned bounding box fully enclosing the object in world space.)

1 Like