Envision, Create, Share

Welcome to HBGames, a leading amateur game development forum and Discord server. All are welcome, and amongst our ranks you will find experts in their field from all aspects of video game design and development.

Newbies guide to Collisions

For RPGs collisions are rather easy as you're only checking either 4 or 8 ways, in a advanced platformer you probably have a physics script running in the background(some betas show curvy lines, diagonals lines etc for showing off their physics scripts)

But today let's worry about the basics, if you can think how something works you can make it work but it's not always the best way to do it.

place_free(x,y)

For an any game this is essential as this is how we check if we;re near a solid, if we're touching solids we just stop movement by "speed=0;" course you may use hspeed/vspeed as well.

Here is just a simple way of moving a character down with collision checking.
Code:
if (keyboard_check(vk_down)) {

 

   if (place_free(x,y+8)) {

 

      motion_set(270,2); // I generally use motion set instead of using hspeed/vspeed or X/Y mainly because I personally find it runs smoother.

 

   }

 

   else {

 

      speed=0;

 

   }

 

}
It's basically the same way for all directions including diagonal directions, just make sure your using code for the right directions.

Direction Easy Guide

Down"South": +

Left"East": -

Right"West": +

Up"North": -


Now for example a diagonal direction. South-East.
Code:
if (place_free(x-8,y+8)) { // movement } else { speed=0; }
Okay, I realize this is probably not the best tutorial ever written as it's far from it. But it get's right to the point without all the jibber jabber.

Enjoy!
 

Thank you for viewing

HBGames is a leading amateur video game development forum and Discord server open to all ability levels. Feel free to have a nosey around!

Discord

Join our growing and active Discord server to discuss all aspects of game making in a relaxed environment. Join Us

Content

  • Our Games
  • Games in Development
  • Emoji by Twemoji.
    Top