Horizontal Collisions issues (Fixed)

B

bigbrainguy

Guest
In my game, I'm trying to get my horizontal collisions to work. When my player collides with the obj_platform horizontally, he can go through the platforms. When in the platforms, the player can't jump but can move left or right through the blocks. However, I used about the same code for my vertical collisions and they work fine. It is probably also good to note that I use these exact same codes in another project I was working on and it worked perfectly fine. The player couldn't go in the platforms at all. I'm pretty loss on why my game is acting this way and was hoping somebody would help.

obj_platform is the platform I'm colliding with that I am going through.

Here is the code:
Code:
//Horizontal Collisions
if(place_meeting(x+hspd,y,obj_platform)){
    while(!place_meeting(x+sign(hspd),y,obj_platform)){
        x += sign(hspd)
    }
    hspd = 0
}

x += hspd
//End Horizontal Collisions
if(place_meeting(x,y+vspd,obj_platform)){
    while(!place_meeting(x,y+sign(vspd),obj_platform)){
        y += sign(vspd)
    }
    vspd = 0
}

y += vspd
If more information is needed I will provide it ASAP.
Thanks for trying to help!
 

Attachments

YoSniper

Member
Is all of the code that sets and uses hspd shown in your post?

I see nothing wrong with this piece of code, which leads me to believe that hspd is being manipulated in another event.

In the DEBUG mode, can you verify that the value of hspd is nonzero as you walk horizontally through the platforms?
 

Slyddar

Member
Collision code looks ok. Check the masks on the solid and player. If you resize an object the mask doesn't get resized, so that could of happened.
 
B

bigbrainguy

Guest
Thanks for the help guys. I found what was wrong with my code and I fixed my game. The issue was that I had two events still in the game that I didn't need. I had key down events for the keys A and D to move left or right. However, these events weren't necessary to the controls and were causing issues with a code I made later for controls. Appreciate the quick responses!
 
Top