• Hey Guest! Ever feel like entering a Game Jam, but the time limit is always too much pressure? We get it... You lead a hectic life and dedicating 3 whole days to make a game just doesn't work for you! So, why not enter the GMC SLOW JAM? Take your time! Kick back and make your game over 4 months! Interested? Then just click here!

Best Kinds of Collisions

I'm making a New Super Mario Bros. style platformer. I've heard that using objects for walls/ground eats up a lot of CPU, so I was looking into replacing them as much as possible.

I know of tile collisions, grid collisions, and vector collisions (vector collisions are basically collisions with lines and polygons, the New Super Mario Bros. games use these for moving/rotating platforms, but unfortunately I have no idea how to make those since GM doesn't have that many vector functions).

Which of these three should I try to implement, and could I modify them to include sloped ground and moving platforms?
 

Genetix

Member
I'd look into using objects - and then instance activation and de-activation instead myself. Should be able to load a room with thousands of objects and still hit a solid 60fps if done correctly.
 
I just use one massive object and place_meeting.

While not the greatest visual demonstration, this demonstrates 1 giant solid object in game.



Even if there are multiple parts, its all just 1 sprite. The sprite is micro and then xscale and yscaled up by 16 or sometimes 64. The xscale / yscale up is done because of image size restrictions. An image / .png can only be so large height and width wise.

Here is a level's .png file for the sprite (this is the real size):



This would be 10 or so screens wide and 3 screens tall.
 
Last edited:

GMWolf

aka fel666
I'd look into using objects - and then instance activation and de-activation instead myself. Should be able to load a room with thousands of objects and still hit a solid 60fps if done correctly.
Eh, instance activation and deactivation is slow and most people don't use it correctly (Tip, don't do it every step).

I just use one massive object and place_meeting.
What, like a single object with precise collision? Slow as well.
But what you can do is group adjacent objects together.

If you use GMS2, use tile collisions for sure! You can still combine it with object collision if you need movable tiles, etc. Video here


If using GMS1.x, use array or grid collisions.
Video here

I would actually recommend you have a look at the tile collision video if you are going to use array or grid collisions as I give much better collision response code, that should be adaptable to the array/grid collision.

Using this grids or arrays is always your best bet: detection will run in the same time regardless of the size or complexity of your level.
 

Genetix

Member
It definitely does have to be implemented correctly - and generally ran every so many steps instead of each. With some proper tweaking you can have over 10,000 instances in a room and keep a solid frame rate, even without any dipping when ran. I do so in my Steam game Rogue Harvest, which is a procedurally generated world loaded with various objects.

It does take some experimentation and adjustments but is a viable option if so!
 

Jase217

Member
There's really no reason not to use tile collisions or your own array/grid collisions if you are able to make atleast most things that you collide with fit into a grid.

It is just so much more efficient than using objects as the engine dosn't have to loop through countless objects and test a collision for each of them, instead with tile collisions you can check the exact spot you need to test, ( For example: the player's feet in a platform game)

It also opens up the possibility of fast destructible environments made up of grid cells if your game needs that kind of thing. I've been using tile collisions for years now and have never gone back.

I would only use object collisions for testing if a bullet hit an enemy object for example, or if there needs to be a moving platform. Using a mix is sensible. Using objects for terrain collisions though is unnecessary.
 

NazGhuL

NazTaiL
I used a lot of tile collision (in fact not tile but ds_grid collision), I change for objects collision recently using @Nocturne Optimise Object.
For small to normal size level I'll use object collision. For larger level I'll stick to tile/grid collision.
I never use deactivation object(except to pause the game). I do much prefer to code simple task/state on the step event when they are 'away' from playing screen. Placed before movement, more complex A.I. and collision then exit the bigger code block.

ie:
step event:
Code:
if(away)
{
scr_regenerate();
scr_clean_floor();
scr_spawn_flowers();
}
else
{
scr_move_to_player_while_generating_1000_particles();
scr_calculate_thousands_of_complex_algorithm();
}
 
Z

zendraw

Guest
how do you make a moving platform in a grid collision system without using objects?
 

NazGhuL

NazTaiL
Haha... I only had in mind wall object!
For moving Platform or an Hydra with 12 tentacles I use object collision. ;)
 
Wow, I actually had no idea that I got any replies on this topic, I must have forgotten to set notifications for it. Thanks for the advice everyone! I'm going to use GMS2's tiles since they seem to be lightning fast.
 
E

Edmanbosch

Guest
I always just use object-based collisions, as I've found them easier to use than tile-based collisions.
 
G

Guest User

Guest
If you use GMS2, use tile collisions for sure! You can still combine it with object collision if you need movable tiles, etc. Video here
i don't want to hijack this thread but i have a question. what do you recommend if we use GMS2 and our tiles AREN'T power of 2?

my tiles are 8x12px, thus not square, and i have no idea what my options are to replace object collisions if i need to. :\
 
I always just use object-based collisions, as I've found them easier to use than tile-based collisions.
That's absolutely true, but my platformer is a pretty huge game and a lot of objects will slow it down, especially since my player objects have a lot of abilities. GMS2 seems to make tile collisions a lot easier though since you can just get the x and y position of a tilemap now.

i don't want to hijack this thread but i have a question. what do you recommend if we use GMS2 and our tiles AREN'T power of 2?

my tiles are 8x12px, thus not square, and i have no idea what my options are to replace object collisions if i need to. :\
I'm curious about this too, I was looking to redo my slopes and collisions entirely so I'm not checking and moving pixel by pixel repeatedly until I hit a wall or something.
 
E

Edmanbosch

Guest
That's absolutely true, but my platformer is a pretty huge game and a lot of objects will slow it down, especially since my player objects have a lot of abilities. GMS2 seems to make tile collisions a lot easier though since you can just get the x and y position of a tilemap now.
What about just stretching the wall object to fit a certain area for collision?
 
What about just stretching the wall object to fit a certain area for collision?
That helps a lot for flat floors and walls, but for slopes it becomes a lot more difficult and you'll often have to place more of them. Either way they'll still have a ton of built in variables to update each frame.
Maybe the upcoming lightweight objects feature will fix that though?
 
E

Edmanbosch

Guest
That helps a lot for flat floors and walls, but for slopes it becomes a lot more difficult and you'll often have to place more of them. Either way they'll still have a ton of built in variables to update each frame.
Maybe the upcoming lightweight objects feature will fix that though?
You can stretch slopes out too for longer slopes.
Do you know if this affects performance at all?
 
You can stretch slopes out too for longer slopes.
Do you know if this affects performance at all?
You can, but depending on how you collide with them, they might not work properly if you use the usual method to move forward until you detect a pixel in front of you and move up by one pixel. That was what I was using before, but now I'm trying to switch to a better collision and movement method for more variety in terrain and a performance boost.
 
E

Edmanbosch

Guest
You can, but depending on how you collide with them, they might not work properly if you use the usual method to move forward until you detect a pixel in front of you and move up by one pixel. That was what I was using before, but now I'm trying to switch to a better collision and movement method for more variety in terrain and a performance boost.
Interesting. I might have to start looking at tile collisions soon.
 
E

Edmanbosch

Guest
Which version of GMS do you use? I would absolutely look at tile collisions if you're using GMS2, but if you're still on GMS1, tiles are way less useful so grids might be the way to go.
I use GMS2.
 

GMWolf

aka fel666
i don't want to hijack this thread but i have a question. what do you recommend if we use GMS2 and our tiles AREN'T power of 2?

my tiles are 8x12px, thus not square, and i have no idea what my options are to replace object collisions if i need to. :\
You can do the snapping using div instead:
x = (bbox_right div tile_size) * tile_size + bbox_right_offset

If the top off my head, bars may need to change a bit.
 
Top