Player Movement with Animation - Devlog 1
For the first Devlog, let's see how I implemented player movement in Unity!
First Steps
I first created a game object for the player. I added a Rigidbody 2D component. This provides all the physics needed for a 2D player!
I also added a collider to ensure that it can collide with walls.
I also made sure to set gravity scale for the Rigidbody to 0 cause we don't want the player to start "falling" since it's a top-down game. ๐
Moving The Player
Moving the player is straightforward! I coded the input using Input.GetAxisRaw() which is a function that gets the directional values from each virtual axis (the axes being Horizonal and Vertical). This allows the player to use both WASD and arrow keys without any extensive code! So when I press D or the right arrow key, this will return a value of 1 for horizontal since it is moving in the right direction. If I press W or up arrow key, it will return 1 in the vertical. The same goes for down and left but with negative 1s. Diagonal movement uses a combination of both values.
Next, I used the Rigidbody within the script to move the position of the player based on input, speed, and position!
I also implemented dash using a speed, cooldown, and timer values so the player can dash between running.
Here is a video showing idle, run, and dash logic!:
Animation
This was the most time consuming thing I did! I had to cycle through about 3-4 different player designs before I chose this one. I animated each one using https://www.piskelapp.com and made sprite sheets for each animation (idle, run, and dash)
Here is an example of a sprite sheet + results (this is for running):
Example of my run blend tree:
Next Steps
I am hoping to complete attacking using a sword and its animations by the next devlog. โ๏ธ
This marks a small but important step for my game! I hope this also helps those making their own games! ๐
See you all in the next devlog! ๐
Descent: The Dungeon Crawler
A Roguelite 2D Dungeon Crawler
Status | In development |
Author | CoralBird |
Genre | Action |
Tags | 2D, Dungeon Crawler, Roguelite |
Accessibility | Interactive tutorial, Textless |
Leave a comment
Log in with itch.io to leave a comment.