Contents
How do you test slopes in platformer physics?
Let’s add the test tile types for the defined slopes. Let’s also create another enumeration for tile collision type. This will be useful for assigning the same collision type to different tiles, for example a grassy 45-degree slope or stone 45-degree slope.
Are there any 2D platform games with collision detection?
Nevertheless, collision detection is an ugly business, and to quote the Queen of Sparta: this will not be easy, you will not enjoy this (and you are very probably not my King). As mentioned there are many types of 2D platform game and collision detection. For this article, I am going to present a demo which does the following:
How is movement split in a 2D platformer?
If a movement for a particular frame is larger than one pixel, then the movement vector is split into many 1px movements, and after each one the conditions for collision with the terrain are checked. This saves us the headache of trying to find obstacles along the line of movement at once, and instead, we can do it iteratively.
What do you need to know about slopes?
Let’s start defining the data that we’ll need to represent the slopes. First of all, we’ll need a height map of a slope, which will define its shape. Let’s start with a classic 45-degree slope. Let’s also define another slope shape; this one will serve as more of a bump on the ground than anything else.
How do you make a slope stick in platformer?
First off, to handle the slope sticking, the mSticksToSlope flag needs to be set, the object must have been on the ground the previous frame, and the move flag needs to be on. Now we need to find the tile to which we should stick.
How big of a file do you need for slopes?
Right now, if the tile size in our game was bigger, say 32×32, each tile type would occupy 8 MB, and if we used 64×64, then it would be 128MB. These amounts seem way too big to be useful, especially if we want to have quite a few slope types in the game.