I was tasked with building an avatar with specific requirements such as actions mapped to controller buttons, animations, etc. We were able to take animations and a model from the Unity Asset store which is where I begun.
After importing the model in I created a folder I created an animation controller for my character. This is so that I can play animations when certain conditions have been met.
In this animation controller, I dragged in the animations that I planned to use and created transitions between them which are activated by the Booleans that i have created in the conditions tab. With all of this set up I can go into the code and sort them out later.
Before that I need to make a character controller so that we are able to move the player character. To do this i create a script and add in variables for speed,rotation,gravity and jumping as well as a vector 3 for the movement direction.
After this I made a function for the player movement this is where most of my code is going to go. In this function i first check if the controller is grounded which essentially means the player is on the ground and then if that is true then check what the input is. if input buttons chosen are pressed then i set the move direction so i can move forward.. While i'm here i can also set the booleans which trigger the animation to true or false. in this case i want to set the is moving bool to true so that the running animation begins to play as the player moves forward.
The problem I had after this was the fact that after beginning movement the player wouldn't stop moving I so to stop this I can check whether the buttons have been released and set the moment direction to 0 which stops the player as well as this I set the, is moving bool to false so that the animation stops as well.
Getting the player to be able to jump was quite simple from here as all I had to was check if another button was pressed (in this case space) and set the move directions y value to the jump. Setting the jumping animation booleans here needs to be done as well. Then in then outside the is grounded statement I -= the y value of move direction by gravity and then multiply that by delta time to create the falling effect.
After the main movement is sorted its time to sort out the attacks that was simple as it was essentially just setting different booleans to true and false from the animator like this.
This feature did the very basic things such as moving in different directions and jumping, however, a lot of the animations turned out very buggy and either didn't play or occasionally glitched the character in the ground.
I also had problems when going in other directions other than forwards as the running animation had some sort of movement attached to it causing the player to move forward a bit no matter which direction they were running in which especially caused problems when the player is running backward as it essentially halved the speed.
Next Task is to build some power ups for the character.
Here is a fixed version of the movement as the original video was lost and I was unable to recreate the problems.
Comentários