N
NoFontNL
Guest
This code should follow the player object, stored in variable follow, but when it reaches a specific x coordinate or y coordinate, it should prevent the view from going past that point. However, when moving the view to the inner side of the room and moving the view back, it doesn't go past the y coordinate with an offset of 64 inwards. (Picture with explanation below)
Camera object:
Left picture: Running this code when the actual edge of the view is past the specific point.
Middle picture: Running te code when you have moved the view more inside the room.
Right picture: Moving the view back to the coordinates in the first picture. (But the view doesn't go to the same position)
Camera object:
Code:
if(instance_exists(follow)){
x+=(follow.x-x)/10;
y+=(follow.y-y)/5;
}
if(instance_exists(follow)){
x=follow.x;
}
if(rectangle_in_rectangle(x-view_wview/2,room_height/2,x+view_wview/2,room_height/2,global.cameraOffset,global.cameraOffset,room_width-global.cameraOffset,room_height-global.cameraOffset) != 1){
while(view_xview<global.cameraOffset){
view_xview++;
}
while(view_xview+view_wview>room_width-global.cameraOffset){
view_xview--;
}
x=view_xview+view_wview/2;
}
if(instance_exists(follow)){
y=(follow.bbox_top+follow.bbox_bottom)/2;
}
if(rectangle_in_rectangle(room_width/2,y-view_hview/2,room_width/2,y+view_hview/2,global.cameraOffset,global.cameraOffset,room_width-global.cameraOffset,room_height-global.cameraOffset) != 1){
while(view_yview<global.cameraOffset){
view_yview++;
}
while(view_yview+view_hview>room_height-global.cameraOffset){
view_yview--;
}
y=view_yview+view_hview/2;
}
Left picture: Running this code when the actual edge of the view is past the specific point.
Middle picture: Running te code when you have moved the view more inside the room.
Right picture: Moving the view back to the coordinates in the first picture. (But the view doesn't go to the same position)
Last edited by a moderator: