Tue, 20.11.2018, 03:00
Welcome Guest | RSS

Vadim @ internetz


Main » 2009 » Oct » 23 » a: great platform collisions
a: great platform collisions
Lets talk a bit about improving collision systems for platform games.
using collision masks1. Using collision masks.
Collision masks are probably the most often newbie mistake. Its not just about platform games. This must be used for any game.
By default, gm will create collision mask for object from all non-transparent sprite pixels to. This is great for static things, but a hell for a player (as you see in example - top images, the character will get stuck in grass more or less often, depending on movement code).
Using collision mask for character is a good way to get rid of random collision bugs
As you see in example, bottom images, even a rectangle mask for player and ground will kill all possible glitches, related to horizontal movement.
Additional note: if you are going to use image_xscale \ yscale, make sure that your collision mask sprite is symetrical around center (else player will have fun by getting stuck in wall when trying to turn around near it).

2. Using move_contact_* functions.
When coding your collision events, this does matter, because by default, after hitting a solid object, both are thrown to xprevious\yprevious. A object that has gravity applied to it, will perform a another fall (duration = square_root( 2*distance_to_ground/gravity )). That detects a inaccurate coding.
To avoid this, make your collision event look like:
vspeed = 0;
//other things that were here for any reason
Note: replace 20 with the maximum movement speed on Y axis. A common mistake is by using arguments (270,-1). When doing that, after hitting any solid from below, character will perform a instant fly into the ground below (if one will exist). So better to set up function arguments well.
3. Step-by-step movement.
The trick here is to allow walking to zero distance to wall, which does not happen in many games for some reason.
To use this, code must be built up like:
repeat (abs(h_speed))
if place_free(x+sign(h_speed),y) {x+=sign(h_speed);}
else h_speed = 0;
You may use for\while loops too ("for better perfomance").
When using this type of movement, you can use h_speed as the hspeed variable, so just change it by small ammounts, and you get non-laggy h-gliding.
Since these are the most common aspects of platform collisions, thanks for reading this article and good luck in your game developing.
Views: 1829 | Added by: Vadim647 | Rating: 4.5/2
Total comments: 1
0   Spam
1 Tamper   (07.11.2009 11:55)
Very good article! :D
I liked it very much.
It is written in a very professional way.
Have you ever thought about publishing all of your examples and tutorials at the GMC?
You'll be seen as a god of some kind xD


Only registered users can add comments.
[ Registration | Login ]
Login form
Entries archive
Tag Board

Online: 1
Guests: 1
Users: 0