• Hey Guest! Ever feel like entering a Game Jam, but the time limit is always too much pressure? We get it... You lead a hectic life and dedicating 3 whole days to make a game just doesn't work for you! So, why not enter the GMC SLOW JAM? Take your time! Kick back and make your game over 4 months! Interested? Then just click here!

help with collision with walls

I wanted to make a game and needed collision for walls for a room with a hallway and most posts here for wall collision don't work, here is my player step script;
Code:
x = x +0;
if keyboard_check(vk_left)
{
    x = x - 3
}
else if keyboard_check(vk_right)
{
    x = x + 3
}
else if keyboard_check(vk_up)
{
    y = y - 2
}
else if keyboard_check(vk_down)
{
    y = y + 2
}
if keyboard_check(ord("A"))
{
    x = x - 4
}
if keyboard_check(ord("D"))
{
    x = x + 4
}
if keyboard_check(ord("W"))
{
    y = y - 4
}
if keyboard_check(ord("S"))
{
    y = y + 4
    end
I don't know if anyone can help me with finding collision for walls or on how to properly make one.

If you need any more information, just ask me, I'm new to gms 2 and just trying to get the basics.
Most of the scripts I've seen people use, still makes my character phase through the wall.
 

ultraboy

Member
GML:
var LEFT=keyboard_check(ord("A"));
var RIGHT=keyboard_check(ord("D"));
var left=keyboard_check(vk_left);
var right=keyboard_check(vk_right);
var dx1=RIGHT-LEFT,dx2=left-right,sp1=4,sp2=2;
if(!place_meeting(x+dx1*sp1+dx2*sp2,y,obj_wall)){
   //Collision judgment
    x+=dx1*sp1+dx2*sp2;
}
You can try to write your collision code like that.
 
Last edited:

TheouAegis

Member
First off, your movement code is terribly flawed. There is a reason you practically never see people code movement like that. Also, why is WASD movement faster than arrow key movement? Why are horizontal and vertical movement in WASD uniform, but not for arrow keys? What's the point in even using arrow keys? Using WASD and arrow keys at the same time essentially triples vertical movement and more than doubles horizontal movement.

Using your movement code there, save x-xprevious to a variable xdif and save y-yprevious to another variable ydif, then set x to xprevious and y to yprevious, then repeat abs(xdif) times x+=sign(xdif) if there is no wall at x+sign(xdif), then do the same for y.
 
First off, your movement code is terribly flawed. There is a reason you practically never see people code movement like that. Also, why is WASD movement faster than arrow key movement? Why are horizontal and vertical movement in WASD uniform, but not for arrow keys? What's the point in even using arrow keys? Using WASD and arrow keys at the same time essentially triples vertical movement and more than doubles horizontal movement.

Using your movement code there, save x-xprevious to a variable xdif and save y-yprevious to another variable ydif, then set x to xprevious and y to yprevious, then repeat abs(xdif) times x+=sign(xdif) if there is no wall at x+sign(xdif), then do the same for y.
The reasoning behind why I used the arrow keys is because I was testing which one was going to be better because its a high school project and I was testing and forgot to take that part out of the text. sorry about that it if brought any confusion, and I read that it had a lot of flaws and I'm not used to game maker studio coding system, this script was a rough draft, the arrow key system does not work as good as the WASD system. Plus, the arrow key system was going to be a scrapped 2nd player enemy that would toggle on team but i scrapped that idea and changed the plot/theme to a single player campaign, you got any key tips on helping with the movement? I just started using game maker studio 2 three weeks ago, so yeah, I'm not the best at it at ALL.
 

TheouAegis

Member
Okay. So have you tried to implement what I described in the second half of my post? I didn't write it out in code because I was lying in bed typing on my phone. So it was basically like a word problem. I am home sick from work today, so if you cannot properly implement my solution from the previous post, I will have access to my computer and keyboard today the better help.
 
Okay. So have you tried to implement what I described in the second half of my post? I didn't write it out in code because I was lying in bed typing on my phone. So it was basically like a word problem. I am home sick from work today, so if you cannot properly implement my solution from the previous post, I will have access to my computer and keyboard today the better help.
Sorry about not responding, my school is a A-day B-day system and I can only work on it on A-Days, I didn't have enough time to change the lines of code, today is the only time I will have to work on the game, I will not have Wednesday, Thursday, And Friday off of school. then the weekend and I possibly will not be working on it next Monday. I will see if implementing it will help. My phone is a old pone and crashes and barely works so i have to use a public education private school computer. And like I said I'm used to coding but not good at it but i will try my best.
 
Top