camera help

hello, I have an interesting idea when it comes to the camera following the player, but I have no idea how to implement it. so, basically the player will be on one side of the screen such as this. and note the camera follows the player in this positions already.

Untitled.png
and what I would like to do is when I move left the camera slowly transitions to this side instead of just appearing.

Untitled 2.png

hopefully I explained that well enough. here is the code i am currently using just to flip the perspective.
// camera perspective switch
var cam_id = view_camera[0];
var cam_width = camera_get_view_width(cam_id)
var cam_height = camera_get_view_height(cam_id)
x = playert.x;
if keyboard_check(ord("D")){


camera_set_view_pos(cam_id,x-cam_width+850,y-cam_height=5000);

}

else
{
if keyboard_check(ord("A"))
camera_set_view_pos(cam_id,x-cam_width+120,y-cam_height=5000)

any help would be appreciated. Thank you.
 

davawen

Member
For that, you want to use the lerp function, which will take a start, an end and a value from 0 to 1, and then interpolate between the two using that value.

(By the way, you can use the code balise to get it nice looking)
GML:
//Create event
t = 0;

//Step event
if(keyboard_check(ord("A")))
{
    //Do your things

    t = t < 1 ? t + 1/room_speed : t
    /*Test t to see if it's less than 1, if 
    it is add 1 secondth, else, let it be 
    (See ternary operators)*/
}
else t = t > 0 ? t - 1/room_speed : t

var _w = lerp(start_width, end_width, t),
    _h = lerp(start_height, end_height, t);

camera_set_view_size(cam_id, _w, _h);
 
For that, you want to use the lerp function, which will take a start, an end and a value from 0 to 1, and then interpolate between the two using that value.

(By the way, you can use the code balise to get it nice looking)
GML:
//Create event
t = 0;

//Step event
if(keyboard_check(ord("A")))
{
    //Do your things

    t = t < 1 ? t + 1/room_speed : t
    /*Test t to see if it's less than 1, if
    it is add 1 secondth, else, let it be
    (See ternary operators)*/
}
else t = t > 0 ? t - 1/room_speed : t

var _w = lerp(start_width, end_width, t),
    _h = lerp(start_height, end_height, t);

camera_set_view_size(cam_id, _w, _h);
Hello, I appreciate the response but I am a little confused. could you be more specific because I tried what u suggested but it did not work. should I add this in my existing code or just use it in a different object? also I dont know what to put in start width end width. bare with me I just started learning gml. thank you.
 
For that, you want to use the lerp function, which will take a start, an end and a value from 0 to 1, and then interpolate between the two using that value.

(By the way, you can use the code balise to get it nice looking)
GML:
//Create event
t = 0;

//Step event
if(keyboard_check(ord("A")))
{
    //Do your things

    t = t < 1 ? t + 1/room_speed : t
    /*Test t to see if it's less than 1, if
    it is add 1 secondth, else, let it be
    (See ternary operators)*/
}
else t = t > 0 ? t - 1/room_speed : t

var _w = lerp(start_width, end_width, t),
    _h = lerp(start_height, end_height, t);

camera_set_view_size(cam_id, _w, _h);
by the way I was messing around with the code you suggested and I got something to work. what it is doing is stretching the sprites instead of transitioning.
 
Top