P
pixelRaid
Guest
I've been following Shaun Spalding's tutorials. One of his videos mentioned a code for something he called a dynamic camera.
The code was following:
var xTo, yTo;
move_towards_point(mouse_x, mouse_y, 0);
xTo = obj_player.x + lengthdir_x(min(256, distance_to_point(mouse_x, mouse_y)), direction);
yTo = obj_player.y + lengthdir_y(min(256, distance_to_point(mouse_x, mouse_y)), direction);
x += (xTo-x)/25;
y += (yTo-y)/25;
view_xview[0] = -(view_wview/2) + x;
view_yview[0] = -(view_hview/2) + y;
view_xview = clamp(view_xview, 0, room_width - view_wview);
view_yview = clamp(view_yview, 0, room_height - view_hview);
It basically creates a lead room in the direction of the mouse pointer. I tried to follow him as much as possible, went through the video multiple times. But failed to understand the code. I even went through the documentations. The code works fine with my game, but I'm not able to get what's exactly happening here. I would be using it in the future and I don't want to simply copy-paste the code everywhere. I would like to know exactly what's happening in the code and also, why is lengthdir needed?
P.S. I'm new here, so I might be wrong about where to ask this question. I apologize for any inconvenience.
The code was following:
var xTo, yTo;
move_towards_point(mouse_x, mouse_y, 0);
xTo = obj_player.x + lengthdir_x(min(256, distance_to_point(mouse_x, mouse_y)), direction);
yTo = obj_player.y + lengthdir_y(min(256, distance_to_point(mouse_x, mouse_y)), direction);
x += (xTo-x)/25;
y += (yTo-y)/25;
view_xview[0] = -(view_wview/2) + x;
view_yview[0] = -(view_hview/2) + y;
view_xview = clamp(view_xview, 0, room_width - view_wview);
view_yview = clamp(view_yview, 0, room_height - view_hview);
It basically creates a lead room in the direction of the mouse pointer. I tried to follow him as much as possible, went through the video multiple times. But failed to understand the code. I even went through the documentations. The code works fine with my game, but I'm not able to get what's exactly happening here. I would be using it in the future and I don't want to simply copy-paste the code everywhere. I would like to know exactly what's happening in the code and also, why is lengthdir needed?
P.S. I'm new here, so I might be wrong about where to ask this question. I apologize for any inconvenience.