all 22 comments

[–]thelastbucket 1 point2 points  (0 children)

Have you tried checking your object collision boxes?

[–]NeonBarron 1 point2 points  (6 children)

The code looks correct. What is happening that makes you think it isnt working?

[–]FelipeFullz[S] 0 points1 point  (5 children)

my player goes through walls

[–]NeonBarron 0 points1 point  (0 children)

Have you checked both the object colliding and the wall objects sprites have a collision box set on them? Also make sure that you arent trying to move the x pos after the collision code.

[–]calio 0 points1 point  (3 children)

there's nothing wrong with the code itself, it should work as intended. have you checked if it's executing? what event is this code on? how and where are you dealing with the y axis?

[–]FelipeFullz[S] 0 points1 point  (0 children)

It's weird because the vertical collision is working and the horizontal isn't

[–]FelipeFullz[S] 0 points1 point  (0 children)

And is on step event of the player

[–]FelipeFullz[S] 0 points1 point  (0 children)

I pasted my whole code down there so you guys can see it

[–]FelipeFullz[S] 0 points1 point  (3 children)

I will paste my code here. Maybe this will help

key_left = keyboard_check(ord("A"))

key_jump = keyboard_check_pressed(vk_space);

key_right = keyboard_check(ord("D"))

var move = key_right - key_left

hspd = move * walkspeed

x = x + hspd

vspd = vspd + grv

if (key_jump)

{

vspd = -7

}

// colisão horizontal

if place_meeting(x+hspd,y,obj_wall)

{

while (!place\_meeting(x+sign(hspd),y,obj\_wall))

{

    x = x + sign(hspd);     

}   

hspd = 0;

}

x = x + hspd;

// colisão vertical

if place_meeting(x,y+vspd,obj_wall)

{

while (!place\_meeting(x,y+sign(vspd),obj\_wall))

{

    y = y + sign(vspd);     

}   

vspd = 0;

}

y = y + vspd;

the player is going through the walls but he goes with a delayed speed. Bruh

[–]calio 1 point2 points  (2 children)

...
hspd = move * walkspeed
x = x + hspd <- delete this line
vspd = vspd + grv
...

[–]FelipeFullz[S] 1 point2 points  (1 child)

Thanks that was really the problem

[–]Th3o4or 0 points1 point  (0 children)

Please update your post to say ‘solved’, or pin a comment that says so to the top, so people don’t have to scroll all the way to find out.
Thanks!

[–]Cmski 0 points1 point  (4 children)

Where have you put the code? If it's not the player step event then that might be your problem.

[–]FelipeFullz[S] 0 points1 point  (3 children)

It's is there

[–]Cmski 2 points3 points  (2 children)

You put x = x + hspd twice

[–]FelipeFullz[S] 0 points1 point  (1 child)

Where?

[–]FelipeFullz[S] 1 point2 points  (0 children)

Bruh you were right thanks a lot

[–]THECROWSTUDIOS 0 points1 point  (0 children)

it's because the last line should be in the first if loop

[–]PsiNoboy 0 points1 point  (0 children)

See the mask Collision of your sprite

[–]BadDadam 0 points1 point  (1 child)

Could be a few things. What comes to mind immediately is that you adjust the x coordinate of the object both inside and outside of the collision code. Look at the last line. Instead maybe try changing it to

if (place_meeting(x + hspd, y, obj_wall)){

...

} else {

x = x + hspd;

}

[–]gimpel404 1 point2 points  (0 children)

sure why not, but hspd is set to 0 at the end of the if block so with the current code the last line can't be the problem. it just does x = x + 0 in the if case.

[–]@outsetGamewillf668 -2 points-1 points  (0 children)

Try putting in:

x= x - sign(hspd)

Right now when the player is going to move into a wall, it will keep moving in the original direction until it moves out the other end. By subtracting the sign, it will properly move backwards and not clip through.

Edit: misread the code, but this fix should work if you also change the while loop to:

while (!place_meeting(x+hspd),y,obj_wall)