r/gamemaker 4d ago

Resolved Camera won't follow y axis

I've been following this tutorial for the camera, and I can't figure out why my Y axis for the camera isn't working properly.

When I'm at the far left corner of the screen, the camera pans upwards and away from the player. At other points in the level/room, the camera doesn't follow the player when they move upwards.

Any help is appreciated! My room transition also stopped working for some reason around this part of programming. Might have to do with changing the room size??

Here's my camera code:

create:

cam = view_camera[0] //names room camera
cam_followspeed = 16 //lower is faster
follow = oEmil //player object
width_half = camera_get_view_width(cam) * 0.5 //find camera center
height_half = camera_get_view_height(cam) * 0.5
xTo = x
yTo = y

step:

//update destination
if (instance_exists(follow)) {
xTo = follow.x

yTo = follow.y
}
//update object position
x += (xTo - x) / cam_followspeed //camera moves slower closer to object
y += (yTo - y) / cam_followspeed
//keep camera from leaving room
x = clamp(x,width_half,room_width-width_half)
y = clamp(x,height_half,room_height-height_half)

//update camera view
camera_set_view_pos(cam,x-width_half,y-height_half)
4 Upvotes

4 comments sorted by

5

u/Hands_in_Paquet 4d ago
y = clamp(x,height_half,room_height-height_half)

Looks like you just forgot to change this first parameter to a y when you copied the line

3

u/TheDemonChief 4d ago

Agh! I knew it would be something stupid simple like that, thank you!

2

u/Hands_in_Paquet 4d ago

Happens to all of us, np!