Adding sprites to Unity
First of all I implemented sprites that I have acquired into Unity so that I can use them for my game. It's as simple as drag and drop and I will do this for all the sprites and assets that I will be using for my RPG game. As you can see there are different folders for each thing so for example within 'The Player' folder there is an 'attack' folder, this contains all the different frames of the sprite so that when the player has an attack function it will animate smoothly using all the different sprite frames. Same applies to movement.
Setting player size
Here I added my character into the game world and set the player size to my liking, the pixels per unit is what sets the size, I set mine to 240 and the larger number you set the smaller the character will appear in the game world. I don't want my character to be too large or too small so what I set it as is fine for me and my game.
Creating a movement script
I won't go into too much detail about the scripts as I have written comments about each of the functions so it will be easier just posting images of the scripts here and briefly explaining them
This float speed function allows me to set the speed of the player within Unity. SerializeField just means that this specific private function is changeable by the player while remaining private at the same time.
Here is the speed in Unity and I can add any value I want, the higher value means the player will move at faster speeds.
Here is the function that actually allows the player to move and also a separate function that takes the players speed into consideration, so without the direction*speed*time equation the player won't move at the set speed by the player.
Here is some if statements that moves the player based on the keys being pressed. So if the player presses 'W' then the player will move in the up direction and if the player presses 'S' it will go down, and so on.
Conclusion
So in conclusion I have added a player sprite into the world that has basic move functions (WASD movement) and nothing really else. For the future I plan on adding more sprites into the game so that when the player moves in each direction it will face the way it moves. Along with that I want to get a player idle animation working, so that if the player is standing still it isn't just a static image and moves slightly, just to make the game feel more alive.
Here is a GIF of me moving the character at this stage of development (i'm using the WASD keys to move it around)
Comments
Post a Comment