• Hey Guest! Ever feel like entering a Game Jam, but the time limit is always too much pressure? We get it... You lead a hectic life and dedicating 3 whole days to make a game just doesn't work for you! So, why not enter the GMC SLOW JAM? Take your time! Kick back and make your game over 4 months! Interested? Then just click here!

GameMaker how to follow the camera?

idk

Member
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?
 

FoxyOfJungle

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.

GML:
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.
 

idk

Member
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.
 
Top