Back

Wednesday 1.6 | Ledge Grabbing

Platformer Prototype

Ledge grabbing method that doesn't require any additional colliders. (But requires every ledge to be a mesh collider)

Ledge Detection Code

I could've just made it with colliders but felt kinda special today.

  1. Shoot a rays down at differing angles (Amount and angle change controllable)
  2. If hit and surface normal points to the sky get the triangle that was hit
  3. Calculates boundaries for the triangle
  4. Calculate closest point to "hand" position within these boundaries
  5. Snap player in ledge grab pose to this point (Animations not in yet)

(Doesn't work for ledges that are not perfectly going along the x or z axis & doesn't take height into consideration yet)

Debugging

GizmosImage

White rectangle are the boundaries of the triangle, red ray is a no hit, blue hit, green hit and the normal is pointing up. White sphere is the calculated grab point. (The one attached to player is a wall check sphere)

Cleaning up

I also got rid of booleans for controlling the climbing and used an enum to control flow through the climbing process. Before I had a mess of booleans like onLedge, climbing and detectingLedge. Which was a nightmare to manage and debug.

	public enum Mode
	{
		DetectWall,
		Climbing,
		DetectLedge,
		GrabbingLedge,
		Falling
	}

Today's Work

On top of the above explained ledge grabbing and detection.

  • Climbing
    • Can only climb up and sideways
    • Can drop from wall when joystick back enough (Threshold controllable)
    • Can't jump to the when right next to it
    • Minor fixes

Next up are the animations which I fear are going to be a hassle.

Back