GameMaker [SOLVED] How to make camera move slowly towards a new target

G

Guest User

Guest
Hi.
I'm making a cutscene system and I have a script to every action. When the action is done, the script stops executing (I'm not sure if I said that correctly:confused:). But now I need a script that sets a new target to the camera so that the camera starts following the object. But I want it to slowly move from the last target to the new one and when the camera is in the right place I would stop the script and move to the next.

How?o_O
 
G

Guest User

Guest
Ok, I found some kind of solution, but it has some problems. This is the script currently:
Code:
///@description cutscene_camera_moveto_object
///@arg object
///@arg speed
///Sets the camera follow an object

//Set camera to not follow anything.
camera_set_view_target(view_camera[view_current],noone);

//Get view position
var pos_x = camera_get_view_x(view_camera[view_current]);
var pos_y = camera_get_view_y(view_camera[view_current]);

//The speed of moving
var spd = argument[1];

//Move the camera to the new position
var new_x = lerp(pos_x,argument[0].x-camera_get_view_width(view_camera[view_current])/2,spd);
var new_y = lerp(pos_y,argument[0].y-camera_get_view_height(view_camera[view_current])/2,spd);

//Update the view position
camera_set_view_pos(view_camera[view_current],new_x,new_y);

//If camera is near enough to target, set it to view target and end the action
if point_in_rectangle(pos_x,pos_y,argument[0].x-(camera_get_view_width(view_camera[view_current])/2)-5,argument[0].y-(camera_get_view_height(view_camera[view_current])/2)-5,argument[0].x-(camera_get_view_width(view_camera[view_current])/2)+5,argument[0].y-(camera_get_view_height(view_camera[view_current])/2)+5) {
    camera_set_view_target(view_camera[view_current],argument[0]);
    cutscene_end_action();
}
So this makes the camera go to the object position and when it is there, it sets the camera to follow the object and ends the script. It works, but sometimes happens, that the view changes drastically. This has probably something to do with the point_in_rectangle thing. But how would I fix this?

Edit: No, I think the problem is because the camera goes out of the room sometimes and then when setting the target to the object, it quickly goes inside the room. How to prevent it going partially outside the room?
 
Last edited by a moderator:

Kyon

Member
How about, make a object 'obj_view' or whatever, and make the camera follow that object. And just move that object between objects.
using move_towards_point or something, and when distance_to_point < 4 or something it switches.
You can even make the speed of move_towards_point a variable to gradually increase it and decrease it idk.
 
G

Guest User

Guest
How about, make a object 'obj_view' or whatever, and make the camera follow that object. And just move that object between objects.
using move_towards_point or something, and when distance_to_point < 4 or something it switches.
You can even make the speed of move_towards_point a variable to gradually increase it and decrease it idk.
That solution is so clever! But now I think I just got the another one to work and it would be too much work to change the entire camera system. :p Thanks though, I will use that method next time. ;)

Edit: So I didn't get my method to work, so I'm maybe going to use the object method.
 
Last edited by a moderator:
Top