Fangames > Programming Questions

smooth camera

(1/1)

cl0udi:
how to make smooth camera in tower rooms please answer thanks

klazen108:
hi sir pls make new object put this code in events and then put in room thx


--- Code: ---////////////////Create Event:
smoothness_factor=6;

view_object=object_index;
view_vspeed=-1;
view_vborder=view_hview/2;
view_hborder=view_wview/2;


//////////////////////Step Event:
if (instance_exists(player)) {
    target_x=player.x;
    target_y=player.y;
   
    dist=point_distance(x,y,target_x,target_y);
    if (dist>64) {
        x=player.x;
        y=player.y;
        speed=0;
        exit;
    }
}
speed=dist/smoothness_factor;
direction=point_direction(x,y,target_x,target_y);
if (speed<1) speed=0;


////////////////////////////Room Start:
//copy of step event, to prevent flashing on room start

if (instance_exists(player)) {
    target_x=player.x;
    target_y=player.y;
   
    dist=point_distance(x,y,target_x,target_y);
    if (dist>64) {
        x=player.x;
        y=player.y;
        speed=0;
        exit;
    }
}
speed=dist/smoothness_factor;
direction=point_direction(x,y,target_x,target_y);
if (speed<1) speed=0;


--- End code ---

Navigation

[0] Message Index

Go to full version