🦘 Example Script – Platformer Player (with Jump & Animations)

This script creates a 2D platformer-style player with left/right movement, jumping, and keyboard + gamepad support. It is fully compatible with the AnimationController component, automatically playing the animations Idle, Walk, Jump, and Fall if they exist on the object.

💡 Tip: assign this script to the player object and make sure it has collisions enabled. If the object includes an AnimationController with animations named Idle, Walk, Jump, and Fall, the script will detect them automatically with no extra code.

📜 Full Code

// ===================================================
    // 🟡 PLATFORMER_PLAYER.js — Platformer-style movement (with gamepad)
    // ===================================================
    
    let anim;
    
    let iniciado = false;
    
    function Start(obj) {
    
      ShowFPS();
    
      cameraFollowTarget = obj;
      obj.type = "player";
      obj.slopeStep = 15;
      obj.speed = 60;
      obj.jumpForce = 120;
      obj.maxFallSpeed = 1200;
      obj.vx = 0;
      obj.vy = 0;
      obj.onGround = false;
      obj.onPlatform = null;
    
      obj.isClimbing = false;
      obj.isOnLadder = false;
    
      anim = getComponent(obj, "AnimationController");
      if (anim) PlayAnimation(obj, "Idle");
    }
    
    // ---------------------------------------------------
    function Update(obj, dt) {
    
      // ===================================================
      // 🟦 IF THE PLAYER IS ON A LADDER
      // ===================================================
      if (obj.isClimbing) {
        // Mark as grounded to prevent falling
        obj.onGround = true;
    
        // REAL vertical ladder movement
        const climbSpeed = 80;
    
        const up   = IsAnyPressed("ArrowUp", "w", "gamepad_up", "gamepad_dpad_up");
        const down = IsAnyPressed("ArrowDown", "s", "gamepad_down", "gamepad_dpad_down");
    
        if (up)   obj.y -= climbSpeed * dt;
        if (down) obj.y += climbSpeed * dt;
    
        // If the player leaves the ladder trigger
        if (!obj.isOnLadder) {
          obj.isClimbing = false;
        }
      }
    
      // ===================================================
      // 🟥 IF NOT CLIMBING → NORMAL PLAYER LOGIC
      // ===================================================
    
      if (obj.vy > obj.maxFallSpeed) obj.vy = obj.maxFallSpeed;
    
      const s = obj.speed;
      obj.vx = 0;
    
      // ===================================================
      // 🎮 MOVEMENT — keyboard + gamepad
      // ===================================================
      const movingLeft  = IsAnyPressed("ArrowLeft", "a", "gamepad_left", "gamepad_dpad_left");
      const movingRight = IsAnyPressed("ArrowRight", "d", "gamepad_right", "gamepad_dpad_right");
      const jumping     = IsAnyPressed(" ", "gamepad_a");
    
      if (movingLeft) {
        obj.vx = -s;
        obj.flipX = 1;
      }
      if (movingRight) {
        obj.vx = s;
        obj.flipX = 0;
      }
    
      // ===================================================
      // 🦵 JUMP — keyboard + gamepad
      // ===================================================
      if (jumping && obj.onGround) {
        obj.vy = -obj.jumpForce;
        obj.onGround = false;
        if (anim) PlayAnimation(obj, "Jump");
      }
    
      // ===================================================
      // 🧠 ANIMATION LOGIC
      // ===================================================
      if (anim) {
        if (!obj.onGround) {
          if (obj.vy < 0) PlayAnimation(obj, "Jump");
          else PlayAnimation(obj, "Fall");
        } else {
          if (Math.abs(obj.vx) > 0.1) PlayAnimation(obj, "Walk");
          else PlayAnimation(obj, "Idle");
        }
      }
    
      // ===================================================
      // 🧱 Movement with collisions
      // ===================================================
      CallFunction(obj, "moveX", obj.vx * dt);
      CallFunction(obj, "moveY", obj.vy * dt);
    }
    
    // ---------------------------------------------------
    // 🧩 Internal functions
    // ---------------------------------------------------
    
    function moveX(obj, vx) { obj.x += vx; }
    function moveY(obj, vy) { obj.y += vy; }
    
    function OnCollisionEnter(obj, other) {
      
    }
    
    function OnCollisionExit(obj, other) {
     
    }
    

📘 Quick Description

🧩 Automatic animations: this script is already prepared to detect object animations. If the developer adds an AnimationController with Idle, Walk, Jump, and Fall, they will play in real time automatically.