Uncategorized

hello this is Mike and today I’m gonna do a tutorial on how to get route Vaughn motion working between blender and unity 5 I’ll be using blender 2.7 and unity 5 the reason for this tutorial is I had some trouble getting motions based on the character moving forward without sliding in place and applying that root bone motion in unity and it took me a while to figure out so I’m trying to save you guys some time we’re gonna start with a blank blender project I’m going to go ahead and go through modeling a simple chess piece given the use case scenario that in our chess board you might want to animate Keane walking forward or hopping forward and not have to worry about coding that to keep feet from sliding and modeling it in blender I am going to go through the modeling here because I’m going to assume that maybe a novice might come across this and want to start to finish thing I’ll go ahead and put annotations in the video so you can jump forward to the good parts if you already know modeling and rigging in blender so let’s just start with a brand new blender project with our you know default square and we’ll go into edit mode and tap Z to go turn off our extra view and we will hit a to deselect all actually first let’s go ahead and move everything up G to move Z for the z axis control to snap to grid and we’ll move everything up so our origin point is at the bottom of our model a to deselect all be for box and let’s go ahead and move that down and extrude up scale efj extrude s for scale extrude again it will make this pretty simple so I don’t waste a whole lot of time G to move Y for locking on the y axis will lean them forward a little bit so that we know which way is facing in unity extrude again scale again and move again and at this point we’ve got this weird-lookin leaning forward King at number one to go into our front view let’s extrude him up a couple more times leave a little block there since Kings have the crosses on them it’s easy to go back into shaded mode and then we do ctrl T to face select mode we’ll select our two faces there with shift and then we’ll extrude them right-click the camps of the movement and then scale them along the x-axis about like that and tab to exit edit mode there’s our King and in blender I have my unit set up so that one of these squares here is about the size of a meter so just to be predictable in unity I’m going to scale this guy down so he fits neatly inside this box so we will have to edit again all to select everything go down here and make sure that we are scaling around our 3d cursor s to scale and we’ll bring him down like that and his base is a bit big so Z to get out of shaded mode ctrl T to select vertex all to disable be for box and we will just scale this down around that same cursor a B for box G Y move him back all right get out of tab mode go back into there okay at will go with that okay so there’s our King our awesome King model if you are going to be texturing him let’s go ahead and unwrap him so a actually let’s do this right since we may have been beginners so what I want to do is I want to select this control R let’s go ahead and give him a cut right down the side like that and we will use this control e to mark our seam and then we will do all select all our vertices and you for UV unwrap and we’ll just unwrap them and if you want to see what

it looks like we can just drag our split window out go to UV image editor and there yeah that should work if I were doing this for real take a little bit of time to clean up our UV maps but we can go ahead and do image the image will make a UV grid in 24 is fine for our purposes and there we go so if we go back into this window and click on textured mode that is horrible so if we were doing this for real we would actually take the time to go and adjust our you v’s that bothers me let’s see if smart UV project is gonna do any better that does a little better okay so when you’re doing this if you’re new to blender a new UV unwrapping you basically want all these squares to be about the same size to avoid stretching when you do go to text or something anyway enough with that get out of edit mode and there’s our beautiful King this texture this UV texture will not move into unity with the thing unless you apply it over here in your textures area this is just for our reference so enough of that we already took the time to make sure that our origin here is on the King where we want the the center of the model to be so we can just do a to add an armature and we’ll do a single bone over here we will get to our armature section and do x-ray so that we can see it no matter where it is in t tab to enter edit mode and we’ll just move this thing down to about there and we will extrude it with E bring up to there and there is our bump alright to have to get out of edit and then in order to get this export properly we’re not going to use a modifier to apply our armature we’re just going to right click on our object shift right click on the armature control P to parent and we will parent with automatic weights and if you go over here and go into pose mode that means if we grab our route bone and move it around which e-everything moves if we grab our little other bone there and double tap our two free rotate you can kind of lean the King around beautiful right alright so tab to go back into edit mode and we’ll make sure to name this bone route for easy reference and we will name this bone cross part thing all right going back into object mode we can that’s really it for making our object now let’s get into a couple of simple animations let’s see you know it’s been a whole lot of time so let’s go in in order to do animations for videogames what we want to do is we want to get to our dope sheet editor come but instead of a dope sheet we’re gonna go over here to our action editor and so basically we’re going to create individual actions for everything we would want our character to do so let’s get into by I can’t pose mode okay so the first action I like to do I just like to call T pose and with that it’s never going to be used in the game but what it allows me to do is to have the way it modeled my action and my model and set up my our mature I like to get back to that at the start of any new action that starts like this so that’s it we’re just gonna select both of our bones shift and right click and go up here and I to insert a location and rotation keyframe and that’s it that’s our one frame T pose now if we go and make another action and don’t have this one associated anything when we restart blender it’s gonna go away so what we want to do is click on this F here and you’ll see that this act this action is assigned to two different objects entities one is the object that we’re doing that we’re working with and the other one is a fake object that lender keeps to where it doesn’t clean this action up when it restarts and that’s it so now let’s go ahead and make our idle action so we will simply do + to add an action we’ll rename it to idle now one thing I’ve gotten in a bad habit of in something I want you to be watching out for is a lot of time so when I go to

make a new action I’ll go down here by habit and just click and start renaming it that of course over at your other action so don’t do that in the habit of just clicking that F by by default and then he won’t experience the horror of saving and reloading a project and realizing that a complex action he made has been overridden so now we’ve got our idle action let’s just we’ve already got our T pose there so let’s say our idle action is going to be 40 frames long so we’ll go to frame 40 we’ll go up here we have both of our bones selected already so in this window in the window where we’re doing our action we’ll do control C to copy pose you can also do pose copy pose and then since we’re already on frame 40 we will do ctrl V to paste our pose and do insert location rotation the reason I did ctrl-c and ctrl-v it’s just to have it I like to get into I realize I could have just left them in place and done another keyframe but if we had already done a movement here in between I just like to get into the habit of copying and pasting poses okay so actually I don’t want him to wind up in the same place because I’m showing you guys route bone movement so let’s grab him and drag him forward using the control key exactly one Square and then we will eye to insert location rotation again and then we’ve got a dice move it back there let’s go to the middle G and Z to move him up insert location rotation and we limited that to our 40 frames and alt a to play okay ugly ugly but whatever so let’s go a little bit forward from the jump and actually let’s go to home control C copy our pose we’ll go a little bit forward and then control V to copy our pose and I’m gonna rotate his head forward a little bit like he’s getting ready for the jump and then so we select all of our bones and insert a location rotation now the reason I left him in place before he started jumping is that when we go to unity and I’ll explain this again when we get there there’s a little bit of a transition where you jump where you switch from one action to the next and if we’re applying our root bone movement then it’s possible if you have the overlap start here and he won’t be quite on the ground when the next action starts to take place and he’ll start floating around just something to be aware of if your root bone is going to be moving off of the plane of of movement so do the same thing here at the end we’ll copy that post ctrl C move back just a hair control V to paste that pose and we’ll move him back like he’s landing a little bit Reed select that bone insert location rotation alright so now we’ve got this neat little jump forward movement alright so shift left to get back to home and I was doing a jump instead of an idle so we’ll just rename this to jump forward make sure it’s saved and then we will add our real item movement first one to jump back to T pose because those are the key frames so I wanted to start with we will add oh call this one idle make sure we force it to fake alright this one will also do 40 frames just for giggles so ctrl c ctrl v insert location rotation go into the middle and double tap harder rotate just the top one insert location rotation over here double tap our insert location rotation just moving him a little bit basically what that’ll do is when he’s standing idle in the game it’ll laugh all day to play just kind of sit there and look

around again we’re not gonna get too detailed in the keyframes all right well a shift left there’s our idle and he is forced to fake alright so now let’s go back to the jump forward pose that we just made that’s working so let’s make a jump backwards pose just to make this easy I’m gonna basically go here to our 40th frame grab both these bones that’s kind of bugging me there let’s switch this back to median point okay so just grab them and control move him back there insert location rotation and that’s going to look all weird but basically we can go back to here and copy this pose go back to here paste it his head forward a little bit kind of twist it to the side like he was looking back select those insert location rotation and then we go to the first frame copy air pose a star pose kinda like he’s starting to head back double tap our give them a little wind up there and insert location rotation and then in the middle we just basically need to move this back about halfway there insert location rotation and now we’ve got a nice little jump back pose with a little head twist so that we know that we’re looking back all right shift left and it’s forced so we’re good I almost did it again I almost just started renaming here learn that habit alright so we’ll add another pose call this jump right we will force it this time we will hit one and notice that when we hit one we’re looking from behind him because I’m modeling on a-z forward axis here so we will be jumping to the right so there’s that pose let’s go ahead and copy it to here and then on this we know everything is straight it just needs to move to the right so notice we’re back though so let’s go ahead and copy or paste the pose we already have copied and then we will move this right one Square insert location rotation copy that pose go back to here paste insert location rotation and then for this one I’m actually just going to delete it next to delete that’ll get rid of our forward back motion and we’ll just kind of be in the middle but we’ll get into the air insert location rotation all right so just because I’m like that I’m gonna have to go here and rotate that in just a little bit insert location rotation go here rotate that in just a little bit insert location rotation and then we’ve got a nice little jump right that is saved we will add a new jump left it’s gonna be the same thing except obviously they want to move him left instead of right insert location rotation copy/paste clean that right a little bit insert location rotation copy paste in that left a little bit certain location rotation and get to the middle and just

slide them to the left insert location rotation and there is our left jump all right enough with the animating make sure we save that so now we’ve got five different poses here we should have six what did we miss ah because we’re on jump left it’s not going to show us it as an option to switch to okay so anyway there is our King and he does all five actions so now we’re ready to export him let’s get back into object mode deselect everything make sure that our lights and cameras are gone we won’t need them gypsy to Center beautiful King okay so over in unity I’ve already started a blank project called King test so in blender we’re just going to leave everything deselected we’re going to file export FBX and the main settings that we want to worry about here are will do Z forward and Y up we want to make sure that baked animation is on and in la strips or at least all actions is on we don’t have laya strips but those are the main things you want z forward and all actions and baked animation and will navigate to our unity folder and we will go into our king test folder and our assets we will create a new directory called blender you could technically save the blend file in the unity directory and unity does recognize those I’ve had trouble with that in the past so I like to it makes more sense to me organizationally just export FBX is so I keep a folder called blender in there and we’ll call this guy our king and export him and we will go back to unity and our blender folder shows up which is nice okay so let’s go ahead and do our little startup cleanup in unity make our seams folder file let’s save our current scene as Kingdom o dot unity and so let’s start out with a plain right click 3d object plane this will be our chessboard one two three four ten by ten chessboard wonderful alright I’m not gonna bother fixing that right now so go ahead and drag our King onto the chess board let’s get overhead and kind of make sure that he’s centered on one of these squares these squares and unity are also roughly a meter or a meter yeah so these will match up with the larger squares and blender nicely our camera is a bit far off so let’s find him there you are it’s get a little bit closer to our King so we can kind of see what’s going on eater rotate and oh that was ugly Road hint em down and a little left and now he can kind of see what our King is doing alright spending a bit too much time on this but whatever okay so now if we play our game down here nothing happens because we haven’t assigned any animations yet so here’s where it gets kind of fun so what we’ll do is we’ve got our nice little animations built into the FBX here are idle jumps and depots we’re still missing or jump back let’s go fix that real quick that’s bugging me I must have done what I told you guys I was going to try to avoid doing pose mode jump left jump right yeah we’re missing our jump back I must have just renamed it okay so add another one call it jump back and I’m just gonna pause the video while I create this okay I’m not sure what happened as soon as I as soon as I named renamed this pose to jump back and it just appeared so who knows alright but now we do have our jump or jump back

jump left and jump right and our idle so now we can go to file export FBX same file and when we go back to unity it automatically reinforces the file and there are various animations jump back okay so working with our King model we now need an animation controller so we’ve got this animator here but in order to interact with it with our our scripts and stuff let’s go ahead and add an animation controller great folder animator errs and in that folder we want to create an animation control and we’ll call it King nm controller and we’ll select our King object and drag that over to our controller and there we go so when we have this animation controller setup over here on our animator layer if you don’t have this animator window open you can just go to window and open up the animator window and I like to drag it down to my console because I hardly ever use my console and that has basically starts within any state in an entry state and I wish you could zoom these things can you zoom them no okay alright so let’s go ahead and get back to our King object and rather than controlling everything with with scripts I like to use this animator here because it I don’t know how like visual stuff so our default is the first action that we drag in so let’s drag in idle alright there’s our idle go ahead and drag some stuff around since I’m dealing with a small window okay that’ll have to do so we’ve got our idle in here so let’s go ahead and grab our jump forward our jump backwards our jump left and our jump right okay now we’re going to want to transition between these two based on input from our script so let’s just make some billions over here so let’s make idle whoops delete let’s make our forward let’s make our backwards and left and a right and we’ll basically set these states with our script and I’ll show you how to do that in a minute for these actions here I’m going to want to refer to them by name so I’m gonna go up here and rename this one just to idle keep me from having to type armature pipe forward naming is is naming consistently is pretty important if you’re going to be interacting with stuff in your scripts that way you don’t have to jump back and forward back and forth sorry I’m not very good at talking and typing at the same time so bear with me alright so there are four or five motions so now to transition between these we simply right-click on a motion or an action make transition and then drag this line here up to whatever action we’re transitioning to so we’re going to transition to forward well click on that transition we’ve got a little preview here and I’ll go through all this stuff in a second but right now what I want you to worry about is this transition when are we going to do it we’re going to do it under the condition that forward is true that’s it okay now forward back to right-click make transition back to idle we’re going to move them forward back to idle if transition if idle is true easy enough

right okay so same thing idle to right we are going to do if sly that down a little bit more if right it’s true and then from right going back to idle we’re going to do that if idle is true idle to back if back is true back to idle if idle is true idle to left if left is true and left to idle if idle is true okay so left forward back right good okay now remember how when in blender when we animated these things we had a little pause here alright so that we kind of stayed in the same place the reason we did that is because of these transitions in unity if you look right here this area here is the transition area and so since we’re not really we’re coming to the same pose at the end of each of our previous poses right so let’s just slide this to be pretty narrow and then slide the next pose out here and let go and it’ll snap back to wherever you slid the arrow to so that’ll make sure that when we’re transitioning from idle to right and back let’s do it on the back also that’ll make sure that we’re not in mid hop up off the ground when we wind up doing our our stuff so you way up in the air like that get down there on our board okay so there we go now both of those are done let’s take care of the rest of them and again we’re doing this so that we don’t wind up in midair after we transition between two poses since we’re going to be using good motion I can just slide that slide that slide that will get there bear with me and we’ve already done those okay ctrl s to save your scene because we hate to get rid of any work now if we hit play sorry the cameras bugging me there we go now if we hit play we can see that our idle pose runs and then stops so the way to fix that is to go over here to King you can click on each of these individual ones but then you have to go over here and click on edit I just like to go to King and say hey and all my animations on idle I want to loop by time alright and see them jump back I’m not gonna loop on these since we’re just going to be doing them once if you’re gonna be doing multiples you would set loop on those as well but since we’re just doing once we don’t need to worry about setting loop I mean I’m gonna go ahead and do it here just show you that when we do our transitions through code that we will wait to the end of a loop but normally you wouldn’t have to do that so apply play and what happened there okay sorry about that I pause the video to figure out what I had done wrong so basically what I had done wrong was I when I exported I had this thing in the middle of our jump back pose and so it actually exported the

default position as that so what they did is I went back and I set it to our pose shift left to make sure it was that frame 1 and then file export FBX re-explore your file and when I went back to unity he had jumped back to where he wanted where he was supposed to be so where were we okay so now we play and we have our nice idle post going over and over if we sit our forward he jumps backwards and why is he doing that because this is the reason for this whole tutorial is because this is what I was having trouble with and it took me a while to figure out if we go to our king object here we need to apply room motion to the instance of our object and then go to our king object and we have model rig and animations at the top we go to rig tell it where root bone is which is the bone that we named root and apply and then we go over to animations and now you’ll notice that since we selected our root node over there down here we have extra options which is root transform rotation position Y and position X Z so for some reason it chooses brutta node rotation for some and original for the other and that’s what’s making us go backwards we need to drop these down and set them all to original make sure our loop time is applied or our loop time is checked and then apply and then if we go and play look at our looping idle animation and if we set our forward to true your Stott heart start hopping forward now the reason we had to do all that is because if you do not set apply root motion and you don’t have the root set then when he starts hopping forward he’s not gonna move or he’s gonna hop forward and then warp back to a starting point and I’ve even had him hopping backwards so the correct things to do there and I’ll go over him again one more time under rig set your route and then under animations make sure you have loop time set if you want to loop it and if you don’t want to loop it then make sure just make sure that all three of these are set to original got it I can’t hear you answering me so how do we control this through a script now that we’ve got everything working well we’ve got these wonderful things here so let’s go to our instance here and add a new script I will be doing this in c-sharp and we’ll do King movement and then let’s go ahead and create our scripts folder of King movement into scripts and then we will double click to edit in our nifty monodevelop utility ok so what are we going to want here so we are going to want an instance of our animation controller so let’s do animator Adam we’ll grab that on start so we don’t need to make it public and in there start we will do an ‘m equals getcomponent open animator whatever animator is attached to this we’re going to grab that okay now we’ve got a interface to grab information from and send information to this animator component that we have attached and that will

return that information to our script so we are also going to want to get our keystrokes so let’s just use W a s and D and and I realize if you’re coding this for real you would be adding logic to see whose turn it was but right now we’re just trying to demonstrate this root bone movement so let’s just do if input dot get a key down C key code dot W that’ll be moving forward okay so make sure that we’re actually in an idle state to keep us from jumping left or right or going backwards in the middle of a jump so if animator that’s what we assigned up here and we’re going to get what was it get our clip info or to go get current animator clip info state info is what we want yes state info layer 0 equals Oh we’ll see you idle right yep okay so what this line is saying is we’re going to reference our animator which is that animator component whatever state we’re in we want the name of that state so if we go back over here to unity the name of our idle state we change to idle nice and simple right alright so what that’s going to do is if we happen to be in the middle of our forward movement it’s it’s not going to make us start another animation there so if we are an idle then we want to set idle equals false and forward equals true so that’s as simple as animator our animator controller and we are going to set bool because we are dealing with boolean values and we can say Idol true or false now this will work however it’s not very efficient so what we want to do here is declare some integers the reason this is not efficient is because it’s going to have to convert this string to an integer hash every single update frame so it’s a lot better because the set set values for our animator components actually want and image your hash for these strings so we will do int hash Idol int hash forward and hash back and hash left and int hash right and then we will set those one time equals animator dot string to hash Idol word back left right and so sorry again I’m not good at talking and doing at the same time and you know it yeah okay so we’ve got our idol forward back left and right there so we can now change this to hash Idol and there we go so we’re going to set our Idol to false if our animator state info is idle set item to faust and annum dot set bull

hash forward true right beautiful so now if we go back and try that well let’s go ahead and finish up him code first we’re not jumping back and forth else and why are we doing else because we only want one key at a time to be active so if somebody’s just mashing we’re not going to get unexpected results so else copy and paste tidy it up okay so else if ass is down and our animation is idle we’re gonna set out on a Foss and back to true alright I like copy and pasting can you tell a D so if a is down and the status Idol idols false and a is going to be left and D Idol idol Foss right so else if no keys are down and if we’re not Idol because if we are Idol and we haven’t started our other animation yet and we don’t want to just jump right back to idle it takes a little bit for the the animation state to to kick off so if we weren’t if we were to not put this statement in and you hit W and in let go W real quick then then basically it would jump to forward and then jump immediately back to idle on the next frame so pace that down there so we’re going to set idle to true and then we’re going to set H forward edge back its left and H right all to false all right so let’s follow this logic since I was not talking very well while I was showing you so we’ve got our King movement controller we’re gonna grab our animation controller which is these two lines and then we’re going to set hashes for our idle for left and right and back strings so that we can pass integer hashes to our to our set bowls then we are going to check for key presses we are going to check our current animator state to make sure we’re not doing anything silly and we are going to set animation or set idle to false and the direction to true if we are at O if we’re not idle and we’re not pressing the key and that shows me something I missed exclamation point for not idle then we’re going to set idle back to true and everything else back to false so ctrl s to save we will jump back into unity we have an error here oh that error means that over here I’m not supposed to be doing an equals so let’s see let’s do is name that should work better oops his name his name his name and his name

not okay so the reason that wasn’t working is because get current animator state info does not does not return a string it returns a structure if you will and one of those class structures is and his name function and I already messed up idle because I capitalized it no I’m not gonna edit my mistakes out of this video because you guys can learn more from watching me mess up okay so logic loop is sound again his name is being used and that will return a boolean and we save and go back to unity and our bugs are gone okay so now let’s make sure that we have our Idol set to start so that we can have our code grab that and we will hit play and we will sit there an idle over and over until we tap the W and we forgot to change our room motion didn’t we apply room motion save and play okay so there’s idle we tap W and now we jump forward we tap s that’s moving wrong why is that moving wrong ah I’ll tell you why that’s moving wrong because when I showed you over here select our FBX object and go into animations once we have our root node assigned I showed you on the idle motion how to set it all up properly you actually need to do that on all of your actions see how we go down to the jump back and it frickin changes those two root node positioned so on all of our actions here we need to change those original you don’t need to apply in between each one applies kind of an all covering action right I wish there was a way to change this in some sort of default setting if you know how let me know I’m doing it on T pose – just cuz I’m frustrated lupa t pose this one frame okay so now I’ve done that for all of our actions apply now we can play if we tap W to move forward hah what happened I’ll bet you that I screwed up again like I said I’m not gonna go and edit my mistakes out of this video because mistakes are part of production right yep how did I manage to screw this up so badly okay I’m gonna pause the video just to fix this so you don’t have to watch me screaming okay now we have our forward motion fixed apparently I had overridden it with the backward motion lovely back to let you know let’s make sure that the back pose is not has not been overridden back alright forward good they all have F’s next to them which means they’ll be saved and then we file export FBX export back to unity everything will be magically updated we play and we tap W and now we’ll jump forward we tap s now we’ll jump backwards we tap a or D we’ll jump right and a will jump left now one thing that’s kind of bothering me is when I tap the key it’s waiting for our idle pose to finish so one last thing we’ll go to idle and we will say

on the transition from idle to forward we will get rid of this has exit time checkbox I’ll also do that on the transitions to our other poses make sure you don’t do it from because we don’t we do want him to finish his animation in the middle of a jump but if he’s just sitting there idling we don’t care about interrupting that animation so ctrl s to save play and now no matter where we are in the middle of an idle animation he will automatically start his jump and if we pretend that these squares are checkboxes so I select our guy move him into the middle of one of these squares our camera over play and there we go all right so that is how you get root bone motion properly working in unity between the unity and blender this could be used if your character if you have an animation of your character rolling and you don’t want to try to get that working with your you know your stride length and all that stuff you could animate him in place and just move the route bone along with him there’s lots of other situations which this would be handy but that’s how I got it working thank you very much if you have any questions leave them in the comments and I will do my best to answer them have a good day

You Want To Have Your Favorite Car?

We have a big list of modern & classic cars in both used and new categories.