Thursday, 3 October 2024

Animation State Machines Class Demo Part 2

    This is part two, here's a link to part oneWe're Finishing up the ASM today. We're adding the rest of the animations, as well as adding the transitions between all of them, and creating a new map with a GameMode Blueprint. 

Transitioning between States

    Open up back up the ABP_Robo Animation blueprint.


    Left mouse click on the orange edge of Locomotion, search for 'add state' and rename the node 'Hit The Ground'. Dive into this node, and inside the asset browser look for 'Stand_to_prone_retargeted' and drag it into the editor. connect this new node to the result output node.


    You will get a warning saying it will never be attainable. To fix this go back up into RoboStateMachine and double click on the dot in-between the nodes


    Add a variable in the my blueprint tab, name it "Firing!". Drag it into the editor. 


    When you recompile you should get rid of warning/errors. Go back into Robo State Machine, inside the Anim preview editor tab, you can see there's a "Firing!" option under BSSPeed variable. Click on it to test if Quin will hit the ground. 
    If it works Quin should be on the ground. However we haven't set up the transition to get back up. So you have to recompile to get her back.
    Add a new state from HitTheGround. Name it 'FiringRifleLoop'. Inside the transition, create a Time Remaining (ratio) node. 


    Time Remaining (ratio) is keeping track of what the previous animation time is at. If the animation clip is at 1, then it's at the beginning. If it's at 0, then its at the end. It is determined by how much time is remaining. We want it at a little bit before 1 so it blends between the transition.
    Create a less than (<) node. Plug into the top input the time remaining node. For the bottom input node, click on it and promote it to a variable. Rename it to 'Time Left' and change the default value to 0.3.

    What this is doing is it is going to stay in the prior state, wait until its about 2/3 complete (think 1-0.3) and then make the jump to firing. 
    Go into FiringRifleLoop, look for Prone_Fire2_retargeted. In the details tab make sure you go into the details tab and check "loop animation"


    Check if it works by clicking on isFiring Variable.
    Create a new state off of FiringREifleLoop, name it 'BackonYourFeetSoldier!'


    Go into the transition state. Grab the Firing variable into the editor. Get the node "NOT Boolean" and connect it up. We want Quin to stop when Firing is false.

    Remember to Compile to get rid of any warning errors.
    Now go into the Back on Your Feet Soldier node. Look in the asset browser for 'Prone_To_Stand_Retargeted' and connect it up.
    Now when we play, we can check and uncheck the firing variable for quinn to go down, fire, and get back up. But we haven't put her back to her Locomotion, and she becomes stuck after getting back up and can't get back down again. Make a final transition back to Locomotion state
    Inside the transition. Get another Time Remaining Ratio, with a less than node, and get the Time Left variable again. 

    Now Quin should transition between all states.

Talking to the Character Blueprint

    Go into the event Graph for our Anim Blueprint. We wanna know how fast are we really going from our character blueprint. Click on 'Try get pawn owner' return value, and make a 'get velocity' node. 

    The yellow output means it is outputting a vector data type. Make a 'vector length' node and connect it here. It's going to convert that vector into a float value. From your variables drag and drop BSSPeed into the editor and create a 'set BSSPeed' node. Connect it to the Vector Length. 
    Now we want the isFiring variable from the character.
    We need to convert the pawn into a data structure that corresponds to a character blueprint. We need to transform our data representation into an actual instances of a character bluepriont (this is called casting, when you transform a pointer into an actual data class)
    From the Get Param driver, drag off of the return value, look for 'cast to Bp_Quin'
    We're basically saying that this part is a BP_Quinn blueprint, which once we drag off a line from the 'As BP Quin" output, we can look for the "Is Firing" variable from that blueprint.
    TIP: If cast to BP_Quinn is not showing up, load it into memory by double clicking on it in the Content Browser to open its editor. Now try finding the 'cast to BP_Quin' node
    Then drag out our Firing variable and make a 'set' node. From the Cast to BP_Quin node, drag out from 'As BP Quin' a "Is Firing?" variable (remember we're able to access this variable from the character blueprint because we're casting). Connect the "Is Firing?" variable to the Set Firing! variable. (Also make sure you're connecting the white line between all of these nodes. 
    

    Understand that casting is slow, you will be urged to stop casting and can take up a lot of memory. It's cumbersome. But it's fast to setup and good for Prototyping. Later we'll use Blueprint Interfaces, which allows you to talk between blueprints. 
    That's all we need to edit from our event graph for our Anim blueprint.

New Map


    We need a special blueprint to talk with the Unreal Engine to tell it what game mode it is. Make a new level, name it MyRoboMap/
    Now create a new blueprint class, look for GameMode (not game mode base, you'll have to go under all classes and search GameMode). Rename it to RoboGameMode.


    All we're doing is changing the default Pawn Class to our BP_Quin.
    Go to world settings, change the GameMode Override to to our RoboGameMode.


Fixing Skating LATER

Go back into our ASM, into the Locomotion State.

NOTE: If you are using ANYTHING other than a character blueprint with an animation blueprint, you have to use 'Get Owning Actor' node instead of 'Try Get Pawn Owner". It will not work otherwise. 

No comments:

Post a Comment

Shader Tool Week 3 - Surface Mapping

 Texture Cubes     Also known as cube maps, its 6 2D texture maps corresponding to the faces of an axis-aligned cube. Used in lighting a sce...