GameMaker: Studio

GameMaker: Studio

Find, play, and make games easily
Discover, rate, and download the best player-created games made in GameMaker: Studio for free. Or try making your own and share with the community. Click here to learn more.
tooth 2 2 Feb, 2013 @ 1:47pm
How to push objects?
I've been getting a bit frustrated, I've been looking through the Game Maker forums for about an hour and I cant find any code that are working for me. I'm working on a top down maze game and I've been stuck with this problem.
< >
Showing 1-4 of 4 comments
Daynar 8 2 Feb, 2013 @ 1:54pm 
Well there are multiple ways to do this but what you can do is check for a collision with the player. If the collision is true check if the player is above below to the left or right of the object, then move the obj by 1 in the opposite direction until collision = false (I'd also have a counter so if it loops through the code more than a few times it breaks from the loop) you could do a similar thing for the maze walls to keep it from being pushed into them. There is probably a better way to do it though.
Last edited by Daynar; 2 Feb, 2013 @ 1:55pm
FinKone 3 Feb, 2013 @ 9:40pm 
Put this little guy in the collision event (exe piece of code) in BOTH objects...

x += 0.1*(x-(other.x))
y += 0.1*(y-(other.y))

small code can do wonders, tweak as needed...
Revalopod 2 21 Jun, 2016 @ 1:09am 
Originally posted by FinKone:
Put this little guy in the collision event (exe piece of code) in BOTH objects...

x += 0.1*(x-(other.x))
y += 0.1*(y-(other.y))

small code can do wonders, tweak as needed...
its kinda shaky...
CatOnMushroom 6 22 Jul, 2016 @ 5:48am 
what kind of movement do you use? on a grid? in such case I have to look back on some projects as one of them contains pushing blocks as a puzzle thingy. blocked by other blocks and walls. worked fine. but like said I have to check that out again, it has been quite a while ago lol. (edit:)
got a part example as it contains alot more to make it work propper but this is the movement I used just checking if it was possible to move:
if (keyboard_check(vk_right)) && (place_meeting(x,y, obj_Gnome_play))
&& place_free(x + 32, y) && (!place_meeting(x + 32,y, TestBlock))
&& (!place_meeting(x + 32,y, BlockBorder))
Last edited by CatOnMushroom; 22 Jul, 2016 @ 5:59am
< >
Showing 1-4 of 4 comments
Per page: 1530 50