G
GMJae
Guest
Hello. This is my first post so apologies if the formatting is not up to standard. I have 2 player objects on the screen. The camera is centered between them. I would like the players to be stopped when they try to go outside of the camera, like Lego Star Wars co-op, but top down. Here is the code I have so far:
This works for left, right and down, but for some reason when I move up instead of stopping the moving player it drags the other with it. Anyone have a fix? Let me know if you guys need more clarification. Thank you in advance.
("yCenter" is the middle of the player object, since I have the sprite origin at the bottom. When I try just using "y", it drags towards the bottom instead).
GML:
//Camera Step Event
following = [obj_player1, obj_player2];
x += (xTo - x);
y += (yTo - y);
xTo = (following[0].x + following[1].x) / 2;
yTo = (following[0].yCenter + following[1].yCenter) / 2;
camera_set_view_pos(view_camera[0], x - RESOLUTION_WIDTH / 2, y - RESOLUTION_HEIGHT / 2);
//Player Camera Border Code
camRightBorder = camera_get_view_width(view_camera[0]) + camera_get_view_x(view_camera[0]);
camLeftBorder = camera_get_view_x(view_camera[0]);
camDownBorder = camera_get_view_height(view_camera[0]) + camera_get_view_y(view_camera[0]);
camUpBorder = camera_get_view_y(view_camera[0]);
x = clamp(x, camLeftBorder + sprite_width, camRightBorder - sprite_width);
y = clamp(y, camUpBorder + sprite_height, camDownBorder - sprite_height);
("yCenter" is the middle of the player object, since I have the sprite origin at the bottom. When I try just using "y", it drags towards the bottom instead).
Last edited by a moderator: