Legacy GM move the view to a certain location of the room

A

Amazing creature

Guest
When a player enters to a boss area the camera should move towards the boss and stay like that until it's defeated.

I sort of manage to do it, but I discover that if the player moves, while this is happening, it may move a little more to the right or left.

also, it moves first horizontally then vertically instead of moving directly towards it

The obj_camera is what the view follows, and this object follows the player.

obj_camera:
Code:
// follow player
if views = 0
{
   x = obj_player.x
   y = obj_player.y
}
// stop following player and move towards a static object
if views = 1
{
   if x > obj_enter.x
      x -= 8;

   if x < obj_enter.x
      x += 8;

   if y > obj_enter.y
      y -= 8;

   if y < obj_enter.y
      y += 8;


}
What makes the views value change is when it collides with an object that changes it (obj_view0, obj_view1, etc)

I have tried the move_towards_object function, but it shakes when it goes where is supposed to
 
Last edited by a moderator:

Perseus

Not Medusa
Forum Staff
Moderator
I have tried the move_towards_object function, but it shakes when it goes where is supposed to
You need to make the view to stop moving when it is close enough, otherwise it might miss the target over and over as it tries to be perfectly at the position you have specified which might or might not be possible due to the speed at which it is moving. For example, if the target position if 4 pixels right of the current view position and the view moves at a speed of 8 pixels per step, then the view position will be lying 4 pixels right of the target position the next step, creating the same situation again and again which causes the shaking. Hope you get what I mean.
Code:
if (views == 1) {
    if (point_distance(x, y, obj_enter.x, obj_enter.y) > 8) {
        move_towards_point(obj_enter.x, obj_enter.y, 8);
    } else {
        speed = 0;
        x = obj_enter.x;
        y = obj_enter.y;
    }
}
 
Top