This week, I worked on expanding the platforming mechanics with several objects and wall jumping. I've always enjoyed wall jumping in games, it's just a satisfying feeling and a great way to make levels a bit more fun. It's a common staple in any platformer at this point, and I'm glad to have figured out how it works. I also worked on several objects like pass-through platforms and springs.
Click read more to go in-depth on what I did this week!
I wanted to implement a few different objects for the player to interact with while platforming, as well as add wall jumping. I ran into some interesting issues I had not foreseen with my player object. To start, let's talk about the rigidbody component in Unity.
To put it simply, the rigidbody component activates Unity's physics engine on the object. Most rigidbodies used in Unity games are "Dynamic" type, which means they listen to Unity's standard gravity, physics and collision settings, among other things. However, my player character is a "Kinematic" type, which means it ignores Unity's default settings and only listens to whatever attached scripts tell it to do. This means you have a great deal of control over the object... It also means you have to code every single interaction the object might have.
Because of this, a lot of Unity tutorials, documentation and standard assets and components... don't work. They want Dynamic type rigidbodies, not Kinematic. But as mentioned last week, I want my game to play better than standard Unity platformers. That means taking matters into your own hands on everything.
To make ladders I had to do the following:
Springs in Spring & Platforms
Off the Wall
This has been a huge wall of text, huh? If only you could jump off it. Wall jumping took a few days to properly get. First of all, I wanted the player to slide down the wall slowly when pressing against the wall, similar to other platformers like Mario, Celeste & Meat Boy. Then, I want the player to jump off the wall by pressing jump. I didn't want my walls to have a script that changes a player's boolean, since I might have to deal with lots of different walls in the future due to tilemaps. That meant I had to get a better understanding of raycasts, arrays, lists and how to handle them. Again, I can't use default collision detection because of the kinematic rigidbody.
Sometimes, that hard work ends up being only a few lines of code. This could've been even smaller: a programmer more gifted in math than me wouldn't need to detect whether something is a "left" or "right" wall. They would calculate the angle of collision, and determine the jumping angle that way. If I wanted to spend a week or more on it, I'm sure I would've been able to do it. But this works just as effectively.
Next week I'm taking a break from programming to work on concept art. I need a way to effectively show what the game will look like to better communicate the idea to people.