Skip to content

Horizontal Collisions

  • Lesson
  • 1 min read
  • 6 of 9 in this chapter

How to make Collision

Now go to your wall object named "obj_wall" and you will see 4 boxes that you can check:

image

Out of these boxes, make sure to check the "Solid" box. Now go to your player object, and remember the code that allows us to move to the right? We will now surround the code with this:

Text
if place_free(x+3,y) {
// this is our original movement code. 
x += 3;

}

What if place_free(x+3,y) is doing here is checking 3px ahead and checking if there is nothing ahead of it. Make sure to do the same for our left key, but instead of "x+3" we are going to do "x-3" in the parentheses.

What's next?

You may notice that we haven't made vertical collision yet, it's because it will be easier to teach it together with gravity.