Player Movement


Intro

Welcome to the first proper devlog for Retro Rumble. This week was all about player movement but also a couple of extra things to get that running smoothly. 

Currently all the sprites for this game are from Kenney, specifically the Platformer Art Pixel Redux, which can be found here: https://www.kenney.nl/assets/platformer-art-pixel-redux.  I'm currently not sure if I'm going to move away from this and maybe make some custom sprites or just stick with these sprite packs.

Fig 1 - Current sandbox layout

Player Movement

I started out making it so the player can move, currently the player can move left and right, jump and also ground pound. I made this possible by using Unity's input system, rather than hardcoding the player's controls. I opted for this approach because this game is planned to be multiplayer and the control scheme aspect of the input system means that the scripts for player movement can be a lot smaller. 

The player game objects have Rigidbody 2D components and their velocity is manipulated through the PlayerController script. All of the values for move speed, jump force and down force are all adjustable in the inspector so they can be easily updated. When moving left and right the value is read from the move call, essentially if they player is moving left using the A or the left arrow key the value will be read as -1 and for right (D/right arrow key) it is read as 1, this is multiplied by the move speed and assigned to the the Rigidbody2D's velocity through a new vector. 

Fig 2 - Player moving back and forth

When the jump key is pressed, the script checks is there are jumps available and if so will remove 1 jump and call the jump method. Inside the jump method, we set the player to not be grounded, and apply the jump force. The reason we are check if they player has jumps available is because the player can double jump so while still in the air they can jump again but will then fall back to the ground because of gravity. When the player's Capsule Collider 2D hits any other collider, the script will check that the collider we hit is below the player and if so sets the player to be grounded and resets the number of jumps they have available. 

Fig 3 - Player jumping and double-jumping

When using ground pound, the script will check if they player is grounded, and if not it means we are in the air and then calls the downforce method, where the downforce is applied to the Rigidbody 2D's velocity. 

Fig 4 - Player using ground pound

Animation

All of the animation were made from the sprite sheets mentioned in the intro.  I made the animations in Unity's window, currently there are only 4 (idle, move, jump and ground pound). They are all on the same timescale to remain consistent and switched between using Boolean conditions in the animator. These Boolean conditions are changed in the update method of the PlayerController Script. An if statement checks for move input, if the player is grounded and if they are using ground pound and sets the animations accordingly. There is another if statement that also reads move input in order to set which way the character is facing. 


Moving Platforms

I wanted to get the moving platforms set up and out of the way, as I thought that might end up being frustrating to get working right. I set them up as a prefab so they can be added into the game where needed more easily. Each prefab consists of the platform game object with the MovingPlatform script and a Box Collider 2D, as well as a set of 2 waypoints. In the start method for the script the first waypoint is set, and then in fixedUpdate the platform's transform is moved towards the target waypoint, it also check if it has reached the target and if so calls the method GetNextWaypoint. GetNextWaypoint returns the next waypoint in the array and if it is at the last one resets to zero. Because the waypoints are in an array, more can easily be added to make them move in some interesting ways. 

Fig 5 - Horizontal moving platform

In order for the player to be able to move with the platforms properly some more methods were need in the PlayerController script. The SetParent function stores the original parent and set the player's parent to that of the platform and ResetParent changes it back to the original parent. Back inside the MovingPlatform script, when the player collides with the platform, it check if what collided was in fact the player and then calls SetParent, when the player stops colliding with it, it calls ResetParent. By making the player a child of the platform it means any movement the platform has is automatically applied to the player, but the player can still move around on the platform.

Fig 6 - Player riding and moving on the moving platform

Most of the code and implementation for these moving platforms was done by PitiIT on Youtube, the video can be found here: https://www.youtube.com/watch?v=frZlZsBX2sU&list=PLZyYVAihdXAjGzCKMbHnaK0nVHoJ-l...


Player Manager

Last but most certainly not least for this devlog is the PlayerManager script. This script handles spawning the players and setting their control schemes. Currently it is only set up to work for 2 player but can be expanded in the future for even more. It's main method is CreatePlayer which picks from an array of spawn points, and the instantiate the selected player prefab at that position and sets the selected control scheme. In the start method CreatePlayer is called twice, first with WASD control scheme and the green player prefab and then again with the arrow key control scheme and the red player prefab. 

Feedback 

Most of the feedback for this week was either quite similar or things for future updates. Most people thought the movement was slow and floaty, So I've dialed up the move speed, jump force and down force to make it more snappy. In the future I'll be looking to add some juice with different effects like Ian suggested.


Thanks for reading, peace :)

Leave a comment

Log in with itch.io to leave a comment.