Download Momentum

Go to the release page on Github and download the latest .unitypackage file.

Importing Momentum

  1. Open or make a new Unity project - it is recommended to use a new project, however, it should work fine on an existing one
    1. Pick the latest stable version (LTS)
    2. Use the 2D or 2D (URP) template
    3. Name your project and set the project location
  2. Import Momentum
    1. Go to Assets → Import Package → Custom Package → then select the .unitypackage from the File Browser
    2. Click on Import
  3. If you were not asked to install the Input System and it is not already installed
    1. Go to Window → Package Manager → Select ‘Packages: Unity Registry’ in the top bar of the window → Search ‘Input System → Click on Install
  4. The files will be located in Assets/Momentum

Configure Momentum

Express Setup

  1. Go to Assets/Momentum/Demo in the Project window
    1. Double click on Demo.unity to open the scene
  2. Set object layers
    1. In the Hierarchy expand the Ground Parent and click on the Ground object
    2. In the Inspector go to Layer → Add Layer
    3. Add the Ground and Player layers on User Layers 3 and 6 respectively. This will automatically set Ground and Player objects to the correct layer. (This might already be set)
      1. To check click on a Ground object and ensure the layer is set to Ground, if not manually set it to the Ground layer. Do the same for Player object
  3. Check Player Data variables are correct
    1. In the Project window go to Assets/Momentum/ScriptableObjects, right the PlayerData.asset file and select Properties
    2. Check that these variables are correctly set, if not follow the instructions below
      • Grounded Layer Mask is set to Ground
      • Wall Layer Mask is set to Ground
      • Cant Exist In is set to Ground
      • Dash Curve is not empty

Bug

The demo scene ledge climb is instant since there is no animation for it, consider adding one.

Manual Setup

You only need assets located in Assets/Momentum/Scripts, the others are only required for the express setup.

  1. Create assets
    1. Right click in the Project window then go to Create → Player Data, this will create a Player Data asset file
    2. Right click → Create → 2D → Physics Material 2D
  2. Create the Player object
    1. In the Hierarchy window right click → Create Empty to create an empty game object. Name it Player (or a name you prefer)
    2. Click on the Player object to select it
    3. Add the following components using the Add Component button in the Inspector window
      • Sprite Renderer
      • Animator
      • RigidBody2D
      • BoxCollider2D
      • Player
      • PlayerChecks
      • PlayerReferences
    4. Go to the PlayerReferences component on the Player object and drag the Player Data asset created in step 1.1 into the field P Data
    5. Go to our BoxCollider2D component and drag the Physics Material 2D we created in step 1.2
    6. Set the Sprite variable on the Sprite Renderer component (The first frame of your Idle animation is fine, or you can use the Default Sprite provided by Momentum)
  3. Create Animation Controller
    1. In the Project window right click → Create → Animation Controller
    2. Add states to the Animation Controller with your own animations (See Assets/Momentum/Animation Controller/CustomAnimator for examples)
    3. Copy the animation names over to the fields in Player component on the Player object if they are different. These fields must match the name of the state that is in the Animation Controller or else they will not be played.
    4. Go to the Animator component on the Player object and drag your Animator Controller into the Controller field
    5. Go to the Ledge Climb animation in your Animation Controller that you created and add an animation event on the last frame using the Animation window (See Assets/Momentum/Animation Controller/Animation/Static Ledge Climb.anim for how the Animation Event looks like)
    6. Select the Player → Go to your Animation window → Click on the dropdown to select the different animations → Select the Ledge Climb animation → Click on the animation event → In the Inspector, go to the Function property and set it to Player → Methods → LedgeClimbAnimationFinished()
  4. Make the Manager object
    1. In the Hierarchy create an empty object. Name it Manager (or a name you prefer)
    2. Add the InputManager.cs component to it
  5. Make the Ground object
    1. Right click in the Hierarchy window → 2D Object → Sprites → Square
    2. Add the BoxCollider2D component
  6. Make Player and Ground layer (and Wall layer if desired)
    1. Click on the Player object, in the Inspector window click on Layer and select Add Layer
    2. Add Ground and Player layers
    3. Go to your Ground and Player objects and set their Layer to their respective layers
    4. Select your Player Data asset and in the Inspector window set the following variables
      • Grounded Layer Mask - Objects to be considered as ground, the Player can only jump from these objects
      • Wall Layer Mask - What is considered a wall? The Player can only perform wall (and ledge) actions on these objects. Most will have this set to whatever Ground is.
      • Cant Exist In - What should the player collide with, ensures the player is not teleported within these objects. This doesn’t handle collisions, but when teleporting the player (like during Ledge Climb) it makes sure nothing within this Layer Mask is in the way.
  7. Finally, set the Dash Curve
    1. Paste the JSON string below into the Dash Curve variable within the Player Data asset. Copy the code, then right click the variable, and click paste

      UnityEditor.AnimationCurveWrapperJSON:{"curve":{"serializedVersion":"2","m_Curve":[{"serializedVersion":"3","time":0.0,"value":0.0,"inSlope":34.68950653076172,"outSlope":34.68950653076172,"tangentMode":0,"weightedMode":0,"inWeight":0.0,"outWeight":0.031713906675577167},{"serializedVersion":"3","time":0.105804443359375,"value":1.0,"inSlope":0.8033333420753479,"outSlope":0.8033333420753479,"tangentMode":0,"weightedMode":0,"inWeight":0.08614794164896012,"outWeight":0.0}],"m_PreInfinity":2,"m_PostInfinity":2,"m_RotationOrder":4}}

Configure Colliders

Box Collider Size and Offset

  1. Go to your Animation window (Window → Animation → Animation)
    1. Select your Player game object
  2. Select the animation you want to set the box collider for, click play, and then pause to stop the animation on a frame There are 4 types of box collider groups contained in the Box Collider section of Player Data
    1. Stand Box Collider - Used by default, unless the state explicitly changes the box collider
      • Example states (non-exhaustive), Idle, Move, Sprint, Jump, Wall Jump, Dash
    2. Crouch Box Collider
      • Used for Crouch Move and Crouch Idle
    3. Ledge Box Collider
      • Used for Ledge Hang and Climb
    4. Wall Box Collider
      • Used for sub-states of WallState → Wall Grab, Climb, Slide
  3. Go to your BoxCollider2D component on the Player and click Edit Bounds
    1. Now return to the Scene window and edit the bounds however you like
  4. Copy the Offset and Size fields on the BoxCollider2D component into the corresponding fields in Player Data, for example
    1. Offset → Crouch Box Collider Offset
    2. Size → Crouch Box Collider Size

Setting Ledge Offsets

When setting the Ledge Offsets make sure the player’s BoxCollider2D does not collide with the ground. You can see the player’s collider by clicking the edit bounds button the BoxCollider2D component.

  1. In the Hierarchy make a Ground object and position it away from other ground objects so that we are able to ledge climb on it
    1. Add the LedgeClimbAndHangOffsetFinder component
    2. Drag the Player object into the Player field
    3. Make sure Show Offset Value is selected
    4. If you’re going to position the player on the left side of the ledge, select Top Left for the Corner field otherwise select Top Right
  2. Enter Play mode
    1. Select the Player and in the Inspector window set the Body Type on the RigidBody2D component to Static
    2. To flip the Player sprite so they are facing the ledge, either use the A and D or check and uncheck the Flip X field on the Sprite Renderer component
  3. Return to the Scene view
    1. Select the Player, go to the Animation window, and select Ledge Hang or Climb animation. Hit play then pause so a frame of the animation shows on the player
    2. Now select the move tool and position the Player near the ledge so it looks like they are grabbing it
  4. In the Console window, a Vector2 will be printed continuously, this is your Ledge Climb/Hang offset (depending on whether you chose to do the Hang or the Climb animation)
    1. Copy this into the Ledge Hang Offset or the Ledge Climb Offset, depending on which animation you chose
  5. In most cases your Ledge Hang Offset will be the same as your Ledge Climb Offset. However, if your Ledge Climb animation’s 1st frame does not look similar to the Ledge Hang animation, then perform the same steps but for the Ledge Climb Animation