Grappling Hook (v1.1)

The Grappling Hook special movement allows your character to fire and swing from a grappling hook.

Priority

The movement should be higher in movement priority than most other movements (air, ground, wall) although it should generally be below a hang from ceiling movement.

Hang from Ceiling

In most cases a Hang from Ceiling special movement will be added above the Grappling Hook special movement. If it is not there the character will detach from the grapple and fall when they hit their head.

Controls

The grapple is controlled by the GRAPPLE button (default: Action Button 0):

  • Pressing once will launch the grapple. If the grapple collides with another collider (as per Physics2D settings of grapple prefabs collider 2D) it latches.
  • When latched with the character standing on the ground, the player can retract the grapple upwards by pressing UP (unless control type set to AUTO RETRACT).
  • When latched with the character off the ground the player can move up and down the grapple by pressing UP or DOWN (depending on the control type setting).
  • If the player presses the GRAPPLE button while swinging they will be launched in to the air.
  • If the player presses the JUMP button while swinging they will break the grapple connection.
  • If the slingshot behaviour is enabled if the player presses and holds the grapple button - while swinging they will be slingshotted up the grapple in the direction of the rope.

 

Settings

Controls

Settings for user controls.

 

Control Type One of UP_AND_DOWN, UP or AUTO_RETRACT. These control how your player can move on the grapple. AUTO_RETRACT will cause the grapple to be reeled in automatically as soon as it latches.
Fire When Grounded Can we fire the grapple while standing on the ground?
Enable Slingshot Can the character slingshot up the grapple by holding the grapple key after latch?

 

Behaviour

Settings for how the grapple behaves.

Max Distance The length of the rope attached to the grapple. Throw further than this and the grapple will disappear.
Retract Speed Speed at which the character moves up or down the grapple.
Acceleration Amount of acceleration to apply to the character on the grapple.
Slow Down Type  Determines how the character is slowed down. 
Drag Factor  The amount of drag used by DRAG and EXPONENTIAL slow down. You can theoretically use positive values to increase speed as you swing. Although large values may have unintended consequences.

Behaviour (Launch & Slingshot)

Settings for how you launch from the grapple.

Launch Velocity Multiplier The swing velocity is multiplied by these values and applied to the character. The natural force of the rope.
Launch Velocity Boost These values are added to the velocity after it is multiplied by the Launch Velocity Multiplier. The extra force imparted by the character when the launch.
Retract Speed How fast to move up the grapple when the slingshot is engaged.
Launch Velocity Speed at which the character is launched (relative to grapple angle).

Note: You generally want some boost velocity, particularly in y to ensure your character pushes up from the grapple.

Warning: The interpretation of these velocity values also depends on the air movement being used.

Note: Usually it looks best if the retract speed and the Launch Velocity values for x and y are the same.

 

Visuals

Settings for the visual components of the grapple.

Hand Offset Controls where the grapple is launched from relative to character centre.
Grapple Prefab Prefab to use for the grapple.
Rope Prefab Prefab to use for the rope.

Warning: Note that the hands X offset will impact the swing of the rope as the character flips directions. For this reasons its best to set up your sprites to use a hand X offset as close to zero as possible.

 

The Grapple Prefab


The Grappling Hook special movement requires a grapple prefab to be configured. The grapple prefab is a GameObject with the special projectile component GrapplingHookProjectile added to it.

The Grappling Hook Projectile GameObject must have a child which contains a 2D rigid body and collider with a ProjectileHitBox attached.

The Grappling Hook Projectile GameObject will usually have another child object which contains the visible portion of the grapple (i.e. a sprite).

Note: Its a good idea to use the prefab from the BionicCop sample to get quickly started with your grapple.

The GrapplingHookProjectile has the following settings:

 

Destroy on Enemy Hit - Inherited from projectile. If true the grapple will be able to latch on to enemies. This should generally be false.

Destroy on Scenery Hit - Inherited from projectile. Must be true to allow grapple to latch to scenery.

Speed - How fast the grapple moves when launched.

Destroy Delay - Inherited from projectile. How long between a hit and the latch even teeing sent. Should usually be 0.

Rotate - Should we rotate to match the direction of travel. Usually true.

Visual Component - Reference to the visual component of the grapple. Turned on and off depending on grapple state.

Projectile Delay - How long to wait after receiving the Fire() event before we actually fire the projectile. Used to sync launch of grapple with animations.

 

The Rope Prefab

The rope prefab is a simple GameObject which is instantiated and then stretched to show the grapples rope. You may wish to draw the rope in a different way by overriding the DrawRope() function of the GrapplingHook movement.

 

Grapple Aiming

As with other projectiles Grapples are aimed using a ProjectileAimer. The grapple will first look for an aimer that it is on the same GameObject as the movement itself. This allows you to use a different aimer for the grapple and for other aiming (such as shooting a gun).

There is a component GrappleProjectileAimer which allows for aiming at 0 (up) and 45 degrees and allows the X velocity of the character to affect the aiming (so if you are running fast instead of shooting at 45 degrees you shoot at a larger angle). This looks better in some scenarios but you can use any aimer, including Mouse Aimer of the second controller stick to aim your grapple.

Have more questions? Submit a request

1 Comments

  • 0
    Avatar
    Roman Fuhrer

    Well documented! Thanks a lot. Is there a way to grapple ony to a certain type of objects?

Please sign in to leave a comment.
Powered by Zendesk