R
Ragedleinad
Guest
HI team, I am having some trouble making the camera follow my object by code
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)
- In the room I enabled the view port for camera 0
- I created the camera object oCamera and added the create and step event
- 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;
- 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);
- Create event
- I Added the object to the room
- 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)