2.5D Paper Mario Style - Unity

Video Statistics and Information

Video
Captions Word Cloud
Reddit Comments
Captions
welcome back everybody to a new Unity tutorial recently I've been playing lots of Paper Mario on the N64 and I really like this 2.5d effect so let's have a go at creating a character and movement in that same Paper Mario Style 2.5d so when you're ready put your arts and craft hat on let's crack on so let's talk character setup my character here is a simple 2D Sprite and attached to him is a capsu collider I've also added a rigid body for the rigid body constraints I have Frozen the rotation on the X and the Z AIS eventually will create a flip effect like that in Paper Mario by changing the angle on the y-axis my character also has some simple animations which I will show you later so I also have an animator component as well at the feet of the character I created an empty Char game object called Ground Checker which I've placed just at the bottom there we are going to use this to cast a ray cast to decide whether or not our character has his feet firmly on the ground to help control things like jumping so when your character is set up go ahead create a player controller script add it to the character and open open it up okay let's just review our movement script we need a public float move speed and a vector 2 of move input for jumping we will apply a public float jump force and a serialized ball jump input for the raycast we want an origin position and that will be a public transform the ground Checker which will be the object at the base of the character the raycast is going to be looking for objects on the ground layer which we will assign shortly and we'll use a layer mask for that a public layer mask which we will call Ground we also want to give the raycast a length so let's add a public float Ray length and once again I have a serialized ball for Grounded this is what will help us to determine whether or not we can jump I'm using a rigid body to move my character so I've added the rigid body as well in the start method let's get the rigid body component like so the RB equals get component rigid body and in the update let's set up our movement so moving left and right will be move input. x equals input. get axis on the horizontal and moving forward and backwards in our 3D space will be the move input doy equals input. GIS vertical there we go that's movement sorted as for the jump I have an if statement here if jump input. getet key down in the brackets I've chosen key Cod space you can choose whatever you like and grounded then jump input equals true now I'm using physics to move this character it's generally good practice to apply your physics in the fixed update so for my movement I would apply velocity the rigid body. velocity equals a new Vector 3 on the x-axis that'll be our move input dox mtip by move speed we don't want to affect the y axis so the rigid body velocity doy will remain the same and we want to move on the Zed axis via our move input doy multiplied by move speeded next is the raycast we'll start with raycast hit hit followed by an if statement if physics. r cast inside the brackets the origin position of the ray that'll be our ground Checker do position we want a direction for it that'll be a vector 3. down out hit feeding back what it's hitting the ray length and the layer mass that it's looking for when the Rayas is hitting a ground object then grounded equals true otherwise grounded equals false to help visualize this in the end engine we have a debug. drawr and once again from the ground Checker do position this time a vector 2. down color red for jumping I've created a void jump method where I'll apply that jump Force by the velocity so the rigid body do velocity equals a new Vector 3 0f on the X jump force on the Y and 0f on the Zed once we have jump jum we want jump input to equal false then back in fixed update if jump input is true then jump there we go that's everything we need for movement let's hit save and head back into Unity back in unity the first thing we want to do is make sure we have objects on a ground layer in my environment here I'll select my ground object go to the layer hit the drop down and I will add a layer that I will call Ground once you've done that let's go back to the player and let's set it up in the inspector for move speed I'll add three for jump Force I will go with five it's asking for a ground Checker transform so drag our ground Checker object in there like so for the ground layer it's currently assigned to nothing we want it to be that ground layer we just created and the ray length let's keep it short something along on the lines of 0.3 there we go hit save and have a little test and we can now run around our 3D scene forward and backwards back to front and you can see that we're currently grounded so hit space or whatever your jump button is assigned and we can now jump in the air like so and you can see that raycast in the scene view there excellent okay let's bring this guy to life with some animations for my animation all I have is a simple idle animation a simple jumping animation and a walk animation I have the same again for when we're moving back towards the horizon idle back jump back and a walk back how we're going to transition between these animations will be in the animator tab using parameters I've already set up my parameters here to create your own own parameters hit the plus and you can choose the variable you like a float int bull or trigger I have a float for my move speed and two balls one for when our back is turned and for when we are grounded I'll go ahead and show you an example of how I've set this up in the animation hierarchy here upon entering the scene we will default to our idle state from idle when we're moving we want to transition to our walk animation to do that right click make a transition and drag it to your desired animation and you'll have a line like this select your transition line I have deselect has exit time and deselected fixed duration and punched in a transition duration of zero for quick Snappy transitions then you can hit the plus and add your parameter your condition and select what you'd like from the dropdown I've chosen Mo speed is greater than 0.1 then transition to walk to revert back to idle the same again but the opposite move speed is less than 0.1 for walking back here the transition will be back turned is true and likewise to revert back to walk from walking back back turned is false let's have a look at walk back to idle back move speed and back turned so if move speed is less than 0.1 back turned is true then idle back and the opposite for walking back back turned is true and the move speed is greater than 0.1 and you can probably Hazard a guess how we transition from idle back to idle back turned simple as that now you may have noticed jump has no transition let's go ahead and do that together we want to be able to jump from any state so right click any state make transition to jump click on the transition make sure there is no exit time no fixed duration and hit zero then let's add our condition we want two conditions here first when we're jumping we're no longer grounded so grounded is false and this will be our normal jump we want back turned equals false then right click any state make transition to jump back and it'll be the opposite so go ahead and do necessaries deselect and hit a zero transition duration two again grounded is false back turned is true to revert back to the idle States we simply want to say that we're grounded so make a transition from jump to jump back once again do the necessaries deselect deselect hit zero condition just the one grounded true and do the same but the opposite for idle back zero grounded is true there we go hit save let's head back into the player controller script and apply these parameters to our inputs okay back in player controller script let's add two more variables as we're dealing with animation underneath the rigid body let's get a reference to the animator animator the anim then let's copy and paste our serialized field for Grounded just pop that underneath and this will be our ball for back turn so go ahead and create that like so now we have the three variables we need to influence those parameters our Mo speed grounded and back turn of course in the start method let's grab that animated component the manim equals get component the animator next let's punch in our parameters for the animations for movement let's go underneath our move input and let's punch in the anim do set float that float parameter we set had the name move speed it's important the spelling matches that which you put and that will be the equivalent of the rigid body do velocity however as we're moving in a 3D space on two different axis even three different axis if we're jumping we only want to get the speed we're not concerned about the values on each respective axis therefore we will add dot magnitude just to get the speed value if our speed is greater than zero then we're moving if it's less than a certain value we're not moving then create a couple of spaces and let's punch in our next parameter the anim do setball back turned and that will be the equivalent of the back turned ball now how are we going to determine whether our back is turned to do that let's above just punch in some if statements and we'll start off by saying if in the brackets our back turned is false and our move input doy is greater than zero therefore we're moving to the background then back turned equals true else if our back is turned and our move input doy is less than zero so we're walking closer to the camera then our back turned equals false and that just leaves one more parameter for jump so let's go ahead and set that beneath our jump input the anim do set ball grounded will equal the ball grounded okay go ahead hit save and let's give that a play test have a runaround in your scene and you can now see that our player character is animated let's check out the back animation that looks fine let's check out jump that looks good let's check out jump back and there we go next let's put the cherry on top and apply that paper Mario rotating flip let's head back into the player controller script to create the flip effect what we're going to do is rotate the character along along the Y AIS we need a few variables beforehand so let's punch in a public ball flipped to determine whether we have or haven't flipped and a public float of flip speed the flipped ball is going to help determine which direction we want the flip to happen if we're moving to the right and we suddenly go left we want to rotate the object 180° left then when we're moving left and going right again we want to rotate back to the default orientation and to do that we're going to use querian let's set two querian flip left and flip right querian flip left equals querian do Ula meaning the angle of the rotation and on the y-axis we'll punch in minus 180° and of course we don't want to affect the X or the Zed if this is your first time encountering the word querian it basically refers to rotation then we'll do the opposite so by default our UL angle will be 0 0 0 and that's what we want to rotate back to when we're flipping and moving back to the right as our character is facing right by default and that will be the Quan flippr equals quaner 0000 now we go we can now use these in our update method and let's place this underneath our anim setf flow move speed let's punch in an if statement that's going to determine whether we have or haven't flipped if we haven't flipped and move input dox is less than zero then flipped is true else if we have flipped meaning we're moving to the left and we suddenly decide we want to move to the right and move input dox is greater than zero then flipped is false okay now we've determined whether flipped is true or false what's going to happen well if flipped is true like we mentioned before we want to rotate the character so he's facing left if flipped is false it's going to rotate back to the right his default orientation so underneath let's apply two more if statements if we're flipped then the transform do rotation of the player will equal Quan do slurp we're going to smoothly interpolate between two rotational values that being the current transform. rotation of the object and our Target rotation is the cunan flip left by the flip speed multiplied by time. Delta time else if we're not flipped we'll do the same again the transform do rotation equals queria do slope the current transform. rotation the Quan flip right by the flip speed multiplied by time. Delta time okay let's hit save let's head back into Unity once everything has compiled let's go ahead and add a flip speed in the inspector nothing too fast I think a value of 10 will be okay then let's go ahead and check it out so have a run around in your scene when you change direction as you can see we have a pretty cool rotating flip effect and I think it adds a nice little touch to the Paper Mario 2.5d Style thank you all very much for joining me today and for checking out our tutorial I hope you found it useful if you did please let us know in the comments or over on any of our socials on X Instagram or Facebook thank you all very much for your continued support and I look forward to seeing you in the next video take okay
Info
Channel: Expat Studios
Views: 230
Rating: undefined out of 5
Keywords: Unity, tutorial, learning, educational, beginner, gaming, development, gamedev, Unity2D, movement, side scrolling, top down, platformer, 2D game, retrogaming, indiegame, platforms, game design, C#, C# tutorial, Unity3D, Paper Mario, Mario, Nintendo, Nintendo64, coding, programming
Id: S1WJ9H-KvKo
Channel Id: undefined
Length: 17min 29sec (1049 seconds)
Published: Mon Jul 01 2024
Related Videos
Note
Please note that this website is currently a work in progress! Lots of interesting data and statistics to come.