GMS 2 Camera not following object only code

R

Ragedleinad

Guest
HI team, I am having some trouble making the camera follow my object by code
  1. In the room I enabled the view port for camera 0
  2. I created the camera object oCamera and added the create and step event
    1. Create event
      Code:
      cam = view_camera[0];//Camera by default
      follow = oPlayer;
      view_w_half = camera_get_view_width(cam) * 0.5;
      view_h_half = camera_get_view_height(cam) * 0.5;
      
      xTo = xstart;
      yTo = ystart;
    2. Step event
      Code:
      if(instance_exists(follow))
      {
          xTo=follow.x;
          yTo=follow.y;
      }
      x += (xTo - x) / 25;
      y += (yTo - y) / 25;
      
      //Update camera view
      x = clamp(x,view_w_half,room_width-view_w_half);
      y = clamp(y,view_h_half,room_height-view_h_half);
      camera_set_view_pos(cam,x-view_w_half,y-view_h_half);
  3. I Added the object to the room
I created a object player oPlayer and I only added it can move right
  1. Step event
    Code:
    if(keyboard_check(ord("D"))){
        x+=8;
    }

Not sure what I am doing wrong, I am following this tutorial, thanks in advanced
GameMaker Studio 2: Complete Platformer Tutorial (Part 6: Cameras & Tiles)
 
R

Ragedleinad

Guest
my only guess as to why its not working is
you enabled the view port but didnt make the view port visible in room properties.
For some reason I enabled the settings in the picture I sent and now it works...xD thank you alot
 
Last edited by a moderator:
Top