D
deathwish
Guest
Hey guys,
I just sort of got into GML and I'm following shaun spalding's tutorial on making a platformer to get started, it's going well so far I understand how the stuff works and have been able to apply certain things in my game that aren't in the tutorial just based of the logic of it.
Regardless; I'm up to the part where he explains how to set up the camera to sort of zoom in and follow the player as they go along and I've got a problem.
So when I set the camera up I had the object following setting in the actual room editor on to my player object
I did all the coding checked if it was the same as on the tutorial etc and I cant see any errors there; but when I tried it out it started off like this:
As my character (grn guy) moves more to the right the camera suddenly moves and starts working as it should but only when im about a third of the way in to room:
Upon troubleshooting I realised that in the video shaun doesn't set and object to follow in the actual room editor; I assumed this would be the fix but when I turned it off the camera was even worse:
as I moved to the right the camera would angle down as it did with an object set to follow but would also exponentially continue going down as I went further to the right:
I can't seem to figure out where I went wrong hopefully you guys can help.
For information:
My room hxw = 1536x648
Camera and viewport = 768x432
The code that was used
Create step:
Thanks!!
I just sort of got into GML and I'm following shaun spalding's tutorial on making a platformer to get started, it's going well so far I understand how the stuff works and have been able to apply certain things in my game that aren't in the tutorial just based of the logic of it.
Regardless; I'm up to the part where he explains how to set up the camera to sort of zoom in and follow the player as they go along and I've got a problem.
So when I set the camera up I had the object following setting in the actual room editor on to my player object
I did all the coding checked if it was the same as on the tutorial etc and I cant see any errors there; but when I tried it out it started off like this:
As my character (grn guy) moves more to the right the camera suddenly moves and starts working as it should but only when im about a third of the way in to room:
Upon troubleshooting I realised that in the video shaun doesn't set and object to follow in the actual room editor; I assumed this would be the fix but when I turned it off the camera was even worse:
as I moved to the right the camera would angle down as it did with an object set to follow but would also exponentially continue going down as I went further to the right:
I can't seem to figure out where I went wrong hopefully you guys can help.
For information:
My room hxw = 1536x648
Camera and viewport = 768x432
The code that was used
Create step:
Code:
Cam = view_camera[0];
follow = obj_player;
view_w_half = camera_get_view_width(Cam) * 0.5;
view_h_half = camera_get_view_height(Cam) * 0.5;
xTo = xstart;
yTo = ystart;
Code:
//Update destination
if (instance_exists(follow))
{
xTo = follow.x;
yTo = follow.y;
}
//Update obj position
x += (xTo - x) / 25;
y += (xTo - y) / 25;
x = clamp(x,view_w_half,room_width-view_w_half);
//update cam position
camera_set_view_pos(Cam,x - view_w_half,y - view_h_half);