GMS 2 how to follow the camera?


I want to look for a way to track the view, I thought with camera_get_view_x(view_camera[0]) I did,
but in that method, there is an inperfection:

2021-02-03 21-52-45 (1).gif

so I was wondering: will there be a way to track the view perfectly?


Kazan Games
This must be happening because there is a small 1 frame delay in the Step Event. To work around this, you can perhaps use the lerp() function and make the camera smooth.
Use camera_set_view_pos() to change the camera's location.

camInd = view_get_camera(0);
camX = camera_get_view_x(camInd)
camY = camera_get_view_y(camInd)
camW = camera_get_view_width(camInd);
camH = camera_get_view_height(camInd);
camXr = camW/2;
camYr = camH/2;

camTX = lerp(camTX, camTarget.x - camXr, 0.2);
camTY = lerp(camTY, camTarget.y - camYr, 0.2);

camTX = clamp(camTX, 0, room_width - camW);
camTY = clamp(camTY, 0, room_height - camH);
camera_set_view_size(camInd, camW, camH);
camera_set_view_pos(camInd, camTX, camTY);
camTarget = Object to follow.


well, by moving the code around like a fool I was able to find a solution.
This solution is to place the code so that the object follows the view in End Step.