Creating a Farming RPG (like Harvest Moon) in Unity — Part 1: Movement

Estimated read time: 1:20

    Learn to use AI like a Pro

    Get the latest AI workflows to boost your productivity and business performance, delivered weekly by expert consultants. Enjoy step-by-step guides, weekly Q&A sessions, and full access to our AI workflow archive.

    Canva Logo
    Claude AI Logo
    Google Gemini Logo
    HeyGen Logo
    Hugging Face Logo
    Microsoft Logo
    OpenAI Logo
    Zapier Logo
    Canva Logo
    Claude AI Logo
    Google Gemini Logo
    HeyGen Logo
    Hugging Face Logo
    Microsoft Logo
    OpenAI Logo
    Zapier Logo

    Summary

    In this tutorial by Terresquall, we dive into creating a Farming RPG in Unity akin to Harvest Moon. The focus is on setting up the basic movement mechanics using Unity's powerful animation and character control features. Terresquall walks us through downloading character models and animations from Mixamo, setting up materials, and configuring the animator along with scripting movement controls using C#. By the end of the tutorial, our character is able to walk, run, and idle smoothly based on keyboard inputs.

      Highlights

      • Kick off your Farming RPG project by downloading free assets from Mixamo and importing them into Unity. 🎬
      • Set up character animations and rigging with Unity’s Animator to bring your models to life. 🎥
      • Learn how to program basic movement states such as idle, walking, and running using C#. 🤖
      • Set up Unity's Input Manager to handle WASD and sprinting controls for character movement. ⌨️
      • Ensure smooth transitions between walking and running animations by adjusting parameters in Unity. ⚙️
      • Wrap up with a functioning player character capable of moving and behaving realistically in your game world. 🌐

      Key Takeaways

      • Explore free animations and models on Mixamo to enhance your Unity projects effortlessly. 🎨
      • Learn to set up basic character movement with animations using Unity's Animator and C# scripting. 🕹️
      • Understand how to implement and control walking, running, and idle states for your game character. 🚶‍♂️
      • Discover how to use Unity's Input Manager to handle keyboard inputs for character movement. 🎮
      • This tutorial is just the beginning—create your farming RPG dreams with these foundational skills! 🌾

      Overview

      In this engaging guide by Terresquall, we're stepping into the world of game development with Unity to create a Farming RPG reminiscent of favorites like Harvest Moon. This first part focuses on mastering character movement. Get started by downloading your character model and animations from Mixamo, a free repository of game-ready assets. The tutorial picks up pace as we delve into Unity, importing these assets, setting up textures, and ensuring our character is fully rigged for animation.

        Next, you'll be propelled into the nitty-gritty of animation in Unity. With a hands-on approach, you'll learn the importance of Animator Controllers, create animations for different movements, and configure them to loop seamlessly. The tutorial breaks down setting up parameters to transition between idle, walking, and running states, providing valuable insight into game development using Unity's robust systems.

          Finally, it’s time to roll up your sleeves and code the movement behaviors. Terresquall expertly guides you through scripting in C# to link animations with user inputs. You'll create a Movement System allowing your character to walk and sprint dynamically, controlled via keyboard inputs. This tutorial is not just instructional but also inspires creativity and problem-solving in adapting to player feedback, preparing you for larger-scale game development projects.

            Chapters

            • 00:00 - 01:00: Introduction and Asset Setup The chapter 'Introduction and Asset Setup' introduces the creation of a 3D Farming RPG project. It starts by discussing the initial steps required in setting up the project, primarily focusing on selecting and acquiring assets. The speaker recommends using Mixamo, a free resource for animations and models, highlighting it as a key part in preparing the necessary elements for the project. The chapter sets the stage for the detailed process of building the game, emphasizing the importance of proper planning and asset acquisition.
            • 01:00 - 03:00: Character and Animation Import In this chapter, the focus is on importing a character for a game and the necessary animations. The process begins with downloading a boy character model and some associated animations that will be used in the development of the game.
            • 03:00 - 05:30: Animator Setup This chapter teaches you how to download a walk animation and integrate it into your Unity project. The emphasis is given to ensuring that the animation is correctly placed, and you are advised not to download the skin. After downloading, the next step is to navigate to your Unity project for further setup.
            • 05:30 - 15:30: Character Movement Script The chapter discusses setting up the initial environment for a project focused on character movement. The process begins with the creation of a new folder, suggested to be named "Imported Assets", which can be filled with either provided assets or personal ones. Following this, a new scene titled "Ranch" is created, serving as the primary setting for the project's activities.
            • 15:30 - 19:00: Running and Sprint Implementation This chapter focuses on implementing running and sprinting mechanics for a player character in a game. The player character, initially without textures, is introduced and solutions for adding textures are provided. First, by selecting the asset and navigating to Materials, textures can be extracted and applied to enhance the character’s appearance.
            • 19:00 - 19:30: Wrap-Up and Conclusion This chapter focuses on the final steps in character modeling, specifically texturing and rigging. Once the model is fully textured, the process moves on to rigging, where you set the animation type to Humanoid and create the avatar definition from the model. Upon application, the character is fully rigged, marking the completion of the modeling process.

            Creating a Farming RPG (like Harvest Moon) in Unity — Part 1: Movement Transcription

            • 00:00 - 00:30 So today we will be creating a Farming RPG. So we'll create it like so. It's a 3D project. And we'll create. So while waiting, let's figure out the assets that we'll need. So what I do is that I go on Mixamo. Mixamo is basically a place where you can get your animations and models for free.
            • 00:30 - 01:00 So here, I'll get a boy character that we'll be using for our game. And I'll download him. We'll also need a couple of animations as well.
            • 01:00 - 01:30 We'll need a walk. So when you download the walk animation, make sure it's in place. We don't need the skin. Press download. When everything is done, go to your Unity project.
            • 01:30 - 02:00 Create a new folder. Let's call this "Imported Assets". You can replace this with assets of your own, but I'll just do this. So we'll import each one. Let's create a new scene. We'll call it "Ranch". This is where we'll be doing most of the things.
            • 02:00 - 02:30 And we'll bring in our character. This will be our player. As you can see, he doesn't have any textures. So what you can do to fix this, is you click on the asset. Go to Materials > Extract Textures.
            • 02:30 - 03:00 Fix Now. And you should see your model fully textured. Now on to the rigging. Go to the model again; go to Rig. Set the animation type as Humanoid. Avatar Definition: Create From This Model. Apply. And now we have a character that is rigged.
            • 03:00 - 03:30 We need to do the same for the animation files to get them working. So go to rig on your running animation. Humanoid. Instead of "Create From This Model", we'll copy from... We'll copy the rig from this model. Do the same with 'Walking'.
            • 03:30 - 04:00 So this will be our Player character. Create a new folder, call it "Prefabs". So this is our Player character. Let's make a new animation for him. Create another folder, call it "Animation".
            • 04:00 - 04:30 First, we need an animator controller, so let's create that. Create > Animator Controller. Name it "Player". Drag it in here. And now on our animator, we can see that there are no animations on it yet.
            • 04:30 - 05:00 Let's go to our imported assets, and there's a "Running" and "Walking" for the player. Let's make duplicates of the animation and rename it. This is "Running", and this is "Walking". Let's bring this to the animation folder; Running and Walking animations.
            • 05:00 - 05:30 In the settings, set it to loop. Set it to loop. Then we can bring them here. Oh. Looks like we need an idle animation as well.
            • 05:30 - 06:00 So now we have 3 animations: Idle, Walking, and Running So by default, our player should be in its idle position. So we set this as the Layer Default State. Make sure this is looped. So how do we control whether it's walking or running?
            • 06:00 - 06:30 Parameters for Speed, and for whether it's running. So if the speed is below 0... Well, greater than 0.1, it would start walking. But when you stop pressing the key, the speed will be less than 0.1, so it will stop walking.
            • 06:30 - 07:00 Now we just have to do this programatically. So, to do this we need a character controller. Now we set the Character Controller properly. Make sure it fits his body nicely.
            • 07:00 - 07:30 Radius... 0.4 looks alright, and now time for the script. Let's create a new folder. Scripts... Create a new C# Script called PlayerController.
            • 07:30 - 08:00 Drag it onto the Player, and edit it with Visual Studio. So we.. As usual we get our MonoBehaviour class. Since we'll be working with the Animator for this we'll need the Animator. Cache this as a variable. We'll also need a CharacterController. Let's call it "controller".
            • 08:00 - 08:30 But just declaring these variables isn't going to help us. We need a way for Unity to know that it's talking about the components attached to this GameObject. So to do this, in our Start function... This is for our movement components.
            • 08:30 - 09:00 So we'll get this from the GameObject, the animator from the GameObject as well. So now if we were to run this, nothing would happen. Because we haven't done anything yet. So let's get it working. So we'll be using the Update function.
            • 09:00 - 09:30 First create the function, called "Move". And then we'll call it on the Update function. So this runs the function that handles all movement. So we want our character to move when we press our WASD keys on the Keyboard. So we can get our input names from Edit > Project Settings > Input Manager.
            • 09:30 - 10:00 So Input Manager is where we'll be making use of the Horizontal and Vertical inputs. So to get them, we have to... in our movement function, represent them as horizontal and vertical values.
            • 10:00 - 10:30 So for example, if I were to press a D key, which is right, the value would be +1. If I don't press anything, it's 0. If I pressed A it would be -1. So this way we can use these values to determine the direction the player's facing.
            • 10:30 - 11:00 So we need to get the direction... So the normalise makes it into 1 unit, with a magnitude of 1, so it doesn't really affect our speed too much. How do we tell if the player should be moving? To check if there is movement, it's when the direction magnitude is greater than... greater or equals to 0.1.
            • 11:00 - 11:30 So if this is the case, it should look towards that direction... and move. To look towards our direction, it's just to set the transform.rotation...
            • 11:30 - 12:00 to Quaternion.LookRotation(). It's that simple. So now if we were to test it... Yeah our character looks in the direction of the key in which we press. This way we know that our direction is working.
            • 12:00 - 12:30 Let's make the camera better... ok. Now we need our character to move. We need to take this direction and multiply it with the speed. To this end, let's declare our move speed.
            • 12:30 - 13:00 We'll make use of velocity; let's calculate velocity. We compute the moveSpeed, direction, with time. And now we'll let the controller do its magic, with the Move command. set in the velocity. And voilà, it should work.
            • 13:00 - 13:30 Our character now moves, but we want it to be playing its animation. So to do that, we will need to use the Speed parameter and link it to its velocity. So make a reference, set the float on the speed to its velocity value.
            • 13:30 - 14:00 So we set it to its magnitude because it only takes in a float value, which we can get by... calculating the magnitude. In this way... huh.
            • 14:00 - 14:30 Okay. We just had to make it less sensitive. And now our character walks and stops. Walk and stop, walk and stop. So the animations are playing correctly.
            • 14:30 - 15:00 Now that our character is able to walk, we need to make our character run. This will be done if he were to hold the Shift key. So let's make our character press the sprint key. As you can see there is no sprint key here, so you have to add one more.
            • 15:00 - 15:30 Call it "Sprint". So now we need to check if the sprint key is pressed. We will use GetButton, which checks if a certain button is currently held down.
            • 15:30 - 16:00 So we check if the sprint button is pressed... being pressed down. So if it is being pressed down, we need to set the animation to run and increase our... move speed. So how do we do that? Let's create a header, call it Movement System.
            • 16:00 - 16:30 This is just for our reference in the inspector. So our walk speed will be set to 4, and for now we'll set our running speed to 2 times of that. So if the sprint key is being pressed down, our move speed will be set to our running speed.
            • 16:30 - 17:00 And if not, set the move speed to our walking speed. So now if you look at it in the inspector, we have our movement system. We can insert our values here, running and walking. If we were to play it now, if I hold shift, my character walks faster, and if I don't... hold shift he walks normally. If I hold shift, my character walks faster, if I do not hold shift he walks normally.
            • 17:00 - 17:30 But you see, the running animation is not doing anything. And this we have to set accordingly. So, how do we transition from walking to running? We set it to run if the Running parameter is true. There's no exit time.
            • 17:30 - 18:00 And it should stop running if the running boolean is set to false. Now we need to reflect that, it's going to set to true if it's sprinting, but if it's not sprinting it's set to false. And there you have it.
            • 18:00 - 18:30 He walks, he runs... If you noticed a bug, if he was to keep running, and I held the sprint key and let go of all... the other keys, he'd still be running. So we have to fix that. Add a transition to go back to idle.
            • 18:30 - 19:00 Speed is less than 0.1. Okay. It works, you just have to remove exit time. And it works perfectly now.
            • 19:00 - 19:30 That's it for this tutorial, hope you enjoyed it, we'll see you at our next tutorial.