• 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!

GML Camera jerks when moving?

Dr_Nomz

Member
So I have this run code:
Code:
if keyboard_check(ord("W")) { var i=run_speed; while !place_free(x,y-i) i--; y-=i; }
if keyboard_check(ord("S")) { var i=run_speed; while !place_free(x,y+i) i--; y+=i; }
if keyboard_check(ord("A")) { var i=run_speed; while !place_free(x-i,y) i--; x-=i; }
if keyboard_check(ord("D")) { var i=run_speed; while !place_free(x+i,y) i--; x+=i; }
if place_free(x+i,y) view_xview+=run_speed;
And the bottom code would go in just after "i=run_speed" and it would follow the player character every time they move.

However, using this method instead of "follow object in room view" makes the character seemingly jerk around whenever they move, like the camera's lagging behind. :/

So any idea how I can fix it so it's just as smooth as using the default room view? (bare in mind it HAS to move with the player, since I also have a cursor code that shifts the camera around.)
 

PlayerOne

Member
I've had this problem before. Place the code that has the view following the player object in the end step event.
 
N

nickvm98

Guest
I've also had a similar problem and consistently adding the view's x coord is not an efficient way of handling camera movement. I recommend along the lines of:
Code:
view_x=median(0,floor(obj_player.x),room_width)
If the view doesn't properly line up with the room then do something like:
Code:
view_x=floor(median(0,global.obj_camera.x-global.view_w/2,room_width-global.view_w));
view_y=floor(median(0,global.obj_camera.y-global.view_h/2,room_height-global.view_h));
In most cases, its better to have a camera object and have its x and y coords as the view x and y and have a global variable which decides which object to follow.
 
Top