JELLE VAN DOORNE - GAME & NARRATIVE DESIGN
  • Home
  • Portfolio
    • Angela's Wedding Disaster
    • Angela's High School Reunion
    • Angela's Fashion Fever
    • Viola
    • Press Q To Stop Time
    • SECRET
  • Blog
  • About
  • Contact
  • Presskit

Wall jumps, platforms and springs

24/3/2018

0 Comments

 
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!
Picture

Kinematic Rigidbodies

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.

Ladders

I started out programming ladders as a way for the player to traverse a lot of vertical ground. I like the short, high-gravity and snappy jump I have currently, but that might limit level design to mostly horizontal levels. Unfortunately, ladders were... a problem.

They turned out to be more complicated to make. I played a few NES games with ladders like Super Mario Bros 2 and Mega Man to get a better feel for how they worked.

The code I ended up with can be seen on the right. This was about the least messy I could get it in the end.
Picture
To make ladders I had to do the following:
  • Have a ladder object (obviously)
  • When the player overlaps with its trigger, if they press up...
  • the player is centered to the ladder.
  • They can not move horizontally.
  • Their position changes vertically according to controller input.
  • When they jump, they let go.
  • When they hit the ground they let go.
  • When they reach the top they let go and can stand on it.
  • When they're at the top of the ladder they can press down to climb it instead.
I got most of this to work, but it didn't feel very good to play. The player often kept moving just a little bit longer when letting go of the controls. They also fell through the floor when going down, and couldn't climb down when standing on the ladder. After two days of trying to figure it out, I cut my losses and went back to the drawing board.

Springs in Spring & Platforms

If all I wanted was to make my player go up high, why didn't I just think of a different way to do it? The first thing that came to mind was a spring. Jump on it or touch and it bo-yoing... up the player goes. This was incredibly simple: if the player object touches the spring, it turns on a bool in the player that adds a lot of vertical force. When the player leaves the object, the bool is turned off. Since the player leaves the object immediately on account of the vertical force, it acts like a single, large jump.
I got pass-through platforms working in about the same amount of time. I first messed around with Unity's default pass-through platforms. However, they only interact with Dynamic rigidbodies. Rather than recreate the entire component, I just made a platform with two colliders. One for the player to stand on, and one that functions as a trigger. If the player enters the trigger, the first collider is removed, and when the player exits the trigger, it comes back. As a result, the player can jump from below (through the trigger) and land on the platform.
Picture
Picture

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.
Picture
The character casts a raycast slightly beyond its collider to detect collision. Every hit is stored in a list, and if the objects we're colliding with have specific tags, turn booleans on or off.
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.
Using the leftWallTouch and rightWallTouch booleans, I was able to implement a walljump separate from the regular jump, making it easy to modify. The wallslide was very simple, just look to inputs and change the gravity modifier.

The jump itself was a bit tougher. During walljumping, I had to disable the player movement for just a little while. Otherwise, the player could continue to hold left against the wall, and not actually move away from it at all. At first, I used coroutines to do so, but calling coroutines from FixedUpdate (used to manipulate physics), is very inefficient and hard to do. Instead, I use a separate boolean, which I turn on and off at specific points during a walljump. Then, by changing the way target velocity is calculated in that moment, I take control away from the player for less than a second and create a walljump for them.
Picture
Picture
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.
0 Comments



Leave a Reply.

    Tweets by GameViola

    About

    This is a development blog for my own game project, "Viola".

    Picture

    Archives

    February 2019
    January 2019
    December 2018
    November 2018
    October 2018
    September 2018
    August 2018
    July 2018
    June 2018
    May 2018
    April 2018
    March 2018
    February 2018

    Categories

    All
    Art
    Design
    Music
    Programming
    Story
    Viola

    View my profile on LinkedIn

    RSS Feed

Site

Portfolio
About
​Contact
  • Home
  • Portfolio
    • Angela's Wedding Disaster
    • Angela's High School Reunion
    • Angela's Fashion Fever
    • Viola
    • Press Q To Stop Time
    • SECRET
  • Blog
  • About
  • Contact
  • Presskit