All projects

Creative / 3D Simulation

Kahlua's Apartment

A browser-based 3D virtual pet simulation with a real AI state machine, a procedurally-built Siamese cat, and a phased product roadmap — built entirely in Three.js.

View on GitHub
3D renderingThree.jsLanguageTypeScriptBuildViteAI architectureFinite State Machine3D approachProcedural geometryTestingVitestDev toolingClaude Code

Overview

The premise started as a question: what would it actually take to build a believable virtual pet in the browser? Not pixel sprites — a 3D space with real physics, behavioral AI, and environmental storytelling. Kahlua's Apartment is the answer: a first-person simulation where you walk through a furnished apartment and interact with a Siamese cat named Kahlua, rendered entirely in Three.js without any external model files.

The direct inspiration is Nintendogs, the 2005 Nintendo DS classic that made a virtual pet feel real through touch: you petted your dog with the stylus, it reacted to where you touched it, and coming back to care for it every day was the whole game. Kahlua's Apartment carries that idea into a 3D browser space: zone-based petting instead of a stylus, hunger and affection that decay in real time, and a planned toy, XP, and shop loop in Phase 2 that echoes the progression that kept Nintendogs players returning.

  • The apartment in first person, with Kahlua on the living-room rug.
  • Aiming at a pettable zone brings up the pet prompt; where you touch changes how he reacts.
  • A built-in Animation QA panel forces any of the cat’s states for testing.

The apartment contains a couch, kitchen counter, refrigerator, bed, dresser, and bathroom — each a real Three.js scene object with collision geometry. Kahlua navigates the space autonomously, using waypoint-based pathfinding to move between rooms while avoiding furniture. His behavioral AI manages hunger, affection, and probabilistic idle selection, so his behavior feels alive rather than scripted. The lighting — warm ambient, a directional sun from west-facing windows with shadow maps, and a sky/ground hemisphere fill — was built to feel like a late-afternoon Chicago apartment.

The architecture is deliberately separated: KahluaGeometry builds the mesh, KahluaAnimator runs the animation state machine each frame, KahluaAI owns behavioral decisions, and KahluaInteraction handles raycasting for touch zones. This separation makes it possible to tune each concern independently — adjusting hunger decay without touching movement code, or swapping animation curves without understanding pathfinding logic.

Built end-to-end with Claude Code, this project demonstrates something specific: the capacity to hold a complex system in a spec document, prototype it cheaply in 2D, validate the core loop, then escalate to a full 3D implementation — with a live phased roadmap tracking what comes next.

AI state machine

Kahlua's behavior is governed by 11 discrete states. Transitions are driven by stat thresholds (hunger triggers a walk to the food bowl), probability weights (idle behavior is randomly selected each cycle), and player interaction (body zone raycasting changes the affection stat and triggers swipe or purr states).

IdleSittingLoafingGroomingKneadingStretchingWalkingSleepingHungryEatingZoomie sprint

Key product & technical decisions

2D prototype before committing to 3D

Before building the Three.js version, a full 2D canvas prototype was built first: a scrolling 3,200px-wide apartment, toy physics, cat movement, and even a Roomba obstacle — all in dependency-free vanilla JavaScript with no build step. The 2D version validated the core loop: does the cat feel alive? Is the space fun to move through? Only after answering yes did the project escalate to the complexity of 3D. That sequencing — build the cheapest version that tests the hypothesis — is PM instinct applied to personal work.

A real AI state machine, not scripted behavior

Kahlua's behavior is driven by an 11-state finite state machine with hunger and affection stats that decay over real time. Idle behavior is probabilistic — a 22% chance of sitting, 10% of loafing, 5% chance of a zoomie sprint on any movement transition. Pathfinding uses waypoints with collision avoidance. Petting triggers state changes depending on which body zone is touched: head and chin are safe; belly contact can trigger a swipe. The result is a cat that feels unpredictable without being random — which is what makes virtual pet behavior feel alive rather than mechanical.

Fully procedural 3D — no model files

The Siamese cat is built entirely from Three.js primitives: cylinders, cones, boxes assembled into an articulated body with moving legs, a segmented tail, blinking eyes, and accurate point coloring. The choice to avoid external model files wasn't a limitation — it was a constraint that forced clear geometric thinking about what makes a cat look like a cat. Every shape is a product decision about visual hierarchy and readability at different camera distances.

Phased roadmap as a living product document

The project's Roadmap.md isn't a completed checklist — it's a proper PM artifact. MVP is done. Phase 1 (richer cat behaviors, environmental interactions) is mostly done. Phase 2 covers a play system, toys, XP, and a shop. Phase 3 outlines room expansion, furniture customization, and a photo mode. Having a phased plan means each session has clear scope, technical debt doesn't accumulate from trying to do everything at once, and the project has a trajectory rather than a horizon.

Product roadmap

MVP

Complete
  • 3D apartment
  • Basic cat movement
  • Hunger system
  • Player locomotion

Phase 1

Complete
  • Full state machine
  • Petting interaction
  • Animated tail & eyes
  • Room lighting

Phase 2

Planned
  • Toy physics
  • Play system
  • XP & progression
  • Item shop

Phase 3

Planned
  • Room expansion
  • Furniture customization
  • Photo mode
  • Achievement system