🪜 Ladder — Script for GameCrom

This script allows a player to climb up and down ladders. The Ladder object must be placed in the scene as a vertical trigger (non-solid), so the player can freely enter and exit the climbable area.

💡 Tip: The Ladder object must have trigger = true and static = true, with no gravity. It only acts as a detection zone — not a solid collider.

📜 Full Code (ladder.js)

// ================================================
// 🪜 ladder.js — Ladder climbing behavior
// ================================================

// Ladders must be TRIGGER objects (not solid)

function Start(obj) {}

function Update(obj, dt) {}

function OnTriggerEnter(obj, other) {
  if (other.type !== "player") return;

  // Enable ladder mode when entering
  other.isOnLadder = true;
  other.isClimbing = true;

  // Cancel velocity to prevent snapping or jitter
  other.vx = 0;
  other.vy = 0;

  // Cancel jump state if active
  other.jumping = false;
}

function OnTriggerExit(obj, other) {
  if (other.type !== "player") return;

  // Leaving the ladder
  other.isOnLadder = false;

  // If climbing, disable climb state
  if (other.isClimbing) {
    other.isClimbing = false;
    other.vy = 0;
  }
}

📘 How It Works

🧠 Tip: For a perfect ladder, create a long and narrow trigger collider covering the entire vertical climbable area.

🧩 Ladder Object Requirements

🎮 How the Player Behaves

The player script checks isOnLadder = true and allows: