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

View/camera preceding player

P

Palocles

Guest
I’ve been following Shaun’s tutorials and have my camera following behind the players character sprite.

How would I change that code to get the camera to be x pixels in front of the player sprite?

I’d like to make the camera be 10 pixels in front when the character walks and 25 when they run. Or something similar.

Thanks.
 
R

Robzoid

Guest
Shaun has it set up so that the oCamera object is in the middle of the view, so you can just set the oCamera's x value to be greater than the player's by a certain amount.

For example in the oCamera object's step event: x = oPlayer.x + 25;

Also, I forget if Shaun Spalding does this, but I like to use the end step event for the oCamera object. It ensures that the player object's movements have been calculated before you calculate your camera's position.
 

TheouAegis

Member
Inside player End Step event:
Code:
camx = x + image_xscale * sign(abs(hspeed)) * (10 + running * 15);
cam_speed = camx - camera_get_view_x(view_camera[0]);
if abs(cam_speed) & ~1
    cam_speed = cam_speed >> 1;
camera_set_view_pos(view_camera[0], camera_get_view_x(view_camera[0]) + cam_speed, camera_get_view_y(view_camera[0]));
Try that. I haven't tested it, just an idea that popped in my head on my way home from work last night.
(final edit at 3:15pm PST)
 
Last edited:
P

Palocles

Guest
Thanks guys. Must have had notifications turned off...

I’ll give them a try soon.
 
Top