Posted September 09, 2023 by georgie
Implementation
The implementation of player movement began with the creation of the Davey's sprites, arranged into a spritesheet. Though I am not quite satisfied with some artistic aspects (e.g., the dreadlocks in the north-facing sprites), it is sufficient for implementing movement.
Davey's spritesheet, drawn by me.
This spritesheet contains a simple walk motion, wherein the middle frame also acts as an idle frame. To bring Davey to life, his spritesheet was converted into multiple sprites by slicing the sheet in Unity, a very convenient feature. The sprites can then be patched together and turned into individual animations for north, south, east, and west walking or idling. Each frame goes for one second, with the middle frame repeating for fluid motion. The speed of the animation can also be conveniently adjusted with Unity; I slowed the motion down to match the movement speed of the character.
Player movement was then implemented by adding a Rigidbody 2D component to Davey, with the gravity set to zero (so that he doesn't fall of the screen!). This Rigidbody2D component allows for physics-based movement by applying forces, and handling collisions. However, more is needed for the player to be moved with controls; that is where our trusty script comes in!
This script enables an entity to move in eight directions based on keyboard input, using the Rigidbody2D component for smooth physics-based movement. The script checks for key presses (W, A, S, D) to determine the direction of movement, updates the associated Animator for animation control, ensuring constant velocity, regardless of the movement angle. When there is no input, the player stops moving, and triggers an idle animation state. This script was adapted from the EightWayMovement script as implemented in the KIT109 practicals.
User Feedback / Improvements
User Feedback was obtained via peer review threads on Discord. Here are the main takeaways:
Alternative Approaches