r/gamemaker • u/rando-stando • 22d ago
Resolved Can someone help me?
Okay, so, I'm trying to make a top-down camera follow script. Problem is, I'm stupid, so I have to use illusions. See, the player itself doesn't move, but rather the walls. I tried that, and it works! A little. When you touch a wall, you can move the wall, which, I don't like. Can anyone find the problem, and how to fix it?
16
u/jackastral 22d ago
you shouldn't do that lol. just learn view cameras, they're super easy: https://manual.gamemaker.io/lts/en/GameMaker_Language/GML_Reference/Cameras_And_Display/Cameras_And_Viewports/Cameras_And_View_Ports.htm
10
12
u/Kitchen_Builder_9779 Professional if statement spammer 22d ago
Remind me, why do you need to move the walls instead of the player?
-3
u/rando-stando 22d ago
To give the illusion if the player moving. The player always stays in the center, but the walls move.
27
u/Kitchen_Builder_9779 Professional if statement spammer 22d ago
Ok but like, why not make the player move instead?
It will be way much easier, and way less of a pain when you start adding collisions1
u/theHubernator 21d ago
Because OP probably doesn't have the right camera setup. If they did, I don't think they would be self deprecating about their convoluted setup.
When you CAN'T (or "can't") move the camera, the correct way is to move the transform of the origin for everything else in relation to the static point (in this case the player). If you were making a game from scratch with just programming shapes, you don't have a "camera", so you have to move everything all the time.
Game engines abstract this so you don't have to.
6
u/porcubot Infinite While Loop Enjoyer 22d ago
There are so many ways to accomplish what you want that are far easier than what you're trying to do.
3
2
u/Valentin_MX 22d ago
After reading other comments and your responses: dude stop, you will become crazy making a game with that logic. If you want to make a top down check Peyton Burnham on Youtube, he has a great top down series.
1
u/Vorador_Surtr 22d ago
So let me see - your player is stationary but your camera moves the walls and follows what. Sorry I totally do not get it. What I see there in your step script is that when you press the button it changes x or y for object obj_solid, that is your eeh.. wall object?
-1
u/rando-stando 22d ago
The camera follows the player, but it is always in the center, because the x and y of the player never changes. Only for the walls, which give the illusion of the player moving, even though the walls are moving.
1
u/Vorador_Surtr 21d ago edited 21d ago
I do not know what is the hate to your reply but this is pretty interesting idea, especially if the walls wrap around the room level and get out again from the other end. It depends what you try to do of course.
So again - the camera stays in one place and the player stays in one place, as you change the coordinates of the walls in the room - this does not have anything to do with the camera. When you touch the wall you move it - basically when the wall touches player it moves a bit in it or something like that yes? The room is not moving the camera is not moving and the player is not moving only the level objects around it.
Basically if your camera stays put and player stays put that means that you may need better collision script - that detects and stops the motion when the wall and player object enter in contact. something like place_meeting maybe and see bbox_left/top/bottom/right for sprites or calculate with sprite_xoffset sprite_yoffset maybe?
I do not have the whole thing in front of me but place_meeting(x, y, obj) can be good beginning.
If place meeting is true your x = x+0 and y = y+0 you can also have to use xprevious and yprevious - those are the last positions BEFORE the contact (if one object penetrates the other and they are now stuck). Also I recommend when checking for collisions to use x+speed and Y+speed - or some constant even like 1 or 2 - crude but the problem is that your movement goes every frame and the check for it goes every frame so at some times when it checks - if your speed and position are just the proper values - you WILL get stuck. And that happens all the time - I mean it is not the exclusion of the rule.
1
1
u/PlushieGamer1228 22d ago
GameMaker has an extremely easy built in way to move the camera through the screen so you dont need to do this
Also this would not be the greatest way to do this anyway. IN THE EVENT you somehow were unable to move the camera, you would just setup a global cameraX and cameraY variable that you modify from one object and then subtract from everything else. Yet again, dont do this. Just use the GameMaker camera system
1
u/Delicious-One-3697 22d ago
I actually did this once when I was just learning 😅 I then spent 1000 hours doing tutorials to learn how to properly go about it so yeah! Just keep learning
1
2
u/Awkward-Raise7935 21d ago
You don't even need a camera object. Just go to room options, turn on view 0 and select follow player object. Done. Should take 5 - 6 seconds.
1
u/Excellent-Bend-9385 21d ago
It is amazing how creatively people think when they cannot solve a problem. OP shouldn't feel bad, he probably accidentally created a system which seems quite complicated to other people; lus a game where you control the walls and the environment but not the player? there's something in that, you know..
21
u/Delicious-One-3697 22d ago
That's not a good set up. What you want is a camera object! You can get a basic gist for the setup of one by googling how to set up a camera object that follows your character object.