Vladimir_spb
Member
Sorry for the mistakes, English is not my first language.
My camera will follow the player, and when he jumps the camera also jumps after him.
How to set up the camera so that when jumping it does not rise, but when the player falls, it moves down following the player.
My camera will follow the player, and when he jumps the camera also jumps after him.
How to set up the camera so that when jumping it does not rise, but when the player falls, it moves down following the player.
GML:
---------------------------------------------------------------------------------------------------------
Сreate
---------------------------------------------------------------------------------------------------------
enum CAM_MODE {
FOLLOW_OBJECT,
FIXED,
FREE
}
cam_mode = CAM_MODE.FIXED;
enum RES {
WIDTH = 640,
HEIGHT = 360,
SCALE = 2 //Zoom.
}
display_width = display_get_width();
display_height = display_get_height();
offset_x = 0;
offset_y = -110;
var _x_border = 128;
var _y_border = 128;
global.CAMERA = camera_create_view(0, 0, RES.WIDTH, RES.HEIGHT, 0, -1, -1, -1, _x_border, _y_border);
view_set_camera(0, global.CAMERA);
window_set_size(RES.WIDTH * RES.SCALE, RES.HEIGHT * RES.SCALE);
surface_resize(application_surface, RES.WIDTH * RES.SCALE , RES.HEIGHT * RES.SCALE );
display_set_gui_size(RES.WIDTH, RES.HEIGHT );
alarm[3] = 1;
follow = noone;
camera_pan_speed_initial = 0.15; //lower = slowed pan
camera_pan_speed = 1;
alarm[CAMERA_RESET] = 3; //alarm [0].
---------------------------------------------------------------------------------------------------------
User event.
---------------------------------------------------------------------------------------------------------
/// @description FOLLOW_OBJECT
if (instance_exists(follow)) {
var _current_cam_x = camera_get_view_x(global.CAMERA);
var _current_cam_y = camera_get_view_y(global.CAMERA);
var _follow_x = (follow.x - RES.WIDTH /2) + offset_x;
var _follow_y = (follow.y - RES.HEIGHT/2) + offset_y;
_follow_x = clamp(_follow_x, 0, room_width - RES.WIDTH);
_follow_y = clamp(_follow_y, 0, room_height - RES.HEIGHT);
var _new_cam_x = lerp(_current_cam_x, _follow_x, camera_pan_speed);
var _new_cam_y = lerp(_current_cam_y, _follow_y, camera_pan_speed);
camera_set_view_pos(global.CAMERA, _new_cam_x, _new_cam_y);
}