Platformer Game

Project description:

This project is a platformer game I am making. There are no specific main inspirations for this project, I just essentially wanted to make a platformer that I would enjoy. Other projects may be more intellectually interesting.

Friction is used to make acceleration more “realistic.” This means the player will accelerate slower when moving uphill and faster when moving downhill. The player also will slide if the angle of the slope is too great (when Ffriction < FgravityParallel).

This page will mostly be about movement mechanics as I haven’t done much level building yet. The player sprite is a placeholder asset I bought a few years ago (made by Elthen’s Pixel Art Shop).

Movement

Running

Acceleration while running is based on the friction the ground has on the character as well as the acceleration variable (higher friction coefficient means more control). The max speed of the character is limited, and if the character goes faster than that it decelerates down to the max value.

Running on Slopes

Slope collision is handled by short raycasts from the player, which when triggered place the player in a position calculated using the position and normal of the cast hit. On steep angles when the gravitational force parallel to the ground is greater than the friction force the player slides.

Wall Jumping

Pressing the jump button while not grounded and in contact with a wall launches the player at a set angle. If a wall jump is done shortly after jumping the angle is higher. While in the air the player accelerates and decelerates slower (air resistance is weaker than friction).

Slope Sliding

The player slides on a slope when the down key is pressed and the angle of the slope is great enough that friction doesn’t stop movement. Landing on a slope while holding down preserves velocity and jumping off a slope jumps at an angle perpendicular to the slope (so jumping off a slope increases horizontal speed, while jumping on flat ground does not). The maximum speed when sliding is increased.

One resource I used for figuring out a good way to handle acceleration was the Sonic Retro Sonic Physics Guide page. It breaks down how the physics of classic Sonic games works. I also used the slope physics and collision sections, though I implemented my own system as some aspects of the Sonic systems are inflexible (every tile has an assigned ground angle, so no freeform shapes can be used).