assets/util/scripts/
├── README.md # Complete scripting guide
├── core/ # Core utilities
│ ├── utils.js # Helper functions (distance, lerp, random, etc.)
│ └── constants.js # Game constants (combat, stats, animations)
├── behaviors/ # AI behaviors
│ └── enemy/
│ └── goblin.json # Example goblin AI behavior tree
├── abilities/ # Character abilities
│ └── warrior/
│ └── slash.js # Example warrior slash ability
├── weapons/ # Weapon behaviors
├── quests/ # Quest definitions
├── events/ # World events
└── ui/ # UI scripts
- Location:
src/scripting/ScriptManager.js - Features:
- ✅ Load JavaScript modules
- ✅ Load JSON data files
- ✅ Script caching
- ✅ Hot-reload support (development)
- ✅ Category-based organization
- ✅ Easy script reloading
-
Core Utils (
assets/util/scripts/core/utils.js):- Math helpers (clamp, lerp, distance)
- Random utilities
- Time formatting
- Debounce/throttle
- And more...
-
Constants (
assets/util/scripts/core/constants.js):- Combat stats
- Character stats
- Enemy types
- Animations
- UI settings
- Physics constants
-
Goblin AI (
assets/util/scripts/behaviors/enemy/goblin.json):- Behavior tree structure
- Combat, chase, and patrol behaviors
- Stats and loot tables
-
Slash Ability (
assets/util/scripts/abilities/warrior/slash.js):- Complete ability class
- Cooldown management
- Damage calculation
- Target finding
- Animation integration
- File:
config/assets.json - Added: Scripts section with paths to core scripts
- Scripting Guide:
docs/SCRIPTING_SYSTEM_GUIDE.md- Complete guide to scripting system
- C# alternatives explained
- "Hinglish" warning fix
- Package recommendations
- Example scripts
NO - C# scripting is NOT natively supported because:
- This is a JavaScript/Babylon.js game (not Unity)
- Runs in web browsers (JavaScript environment)
- No .NET runtime available
- ✅ JavaScript Modules (Recommended) - Native, best performance
- ✅ Lua Scripts - Available from Grudge-PlayGround, good for modding
- ✅ JSON Behavior Trees - Great for AI and data-driven logic
⚠️ WebAssembly - Possible but complex (not recommended)
- FALSE POSITIVE from your IDE
- Language detection plugin misidentifying JavaScript code
Add to .vscode/settings.json:
{
"files.associations": {
"*.js": "javascript"
}
}Or disable the language detection extension.
npm install fengari fengari-webnpm install --save-dev typescript @types/node esbuild viteYour package.json already has:
- ✅
@types/node- TypeScript definitions - ✅
express- Server - ✅
eslint- Linting - ✅
prettier- Code formatting
import { scriptManager } from './src/scripting/ScriptManager.js';
// Initialize with hot-reload for development
await scriptManager.init({ hotReload: true });// Load ability script
const abilityScript = await scriptManager.loadAbility('warrior/slash.js');
const { SlashAbility } = abilityScript.data;
// Create and use ability
const slash = new SlashAbility(player);
await slash.execute(target);// Load behavior
const behaviorScript = await scriptManager.loadBehavior('enemy/goblin.json');
const goblinBehavior = behaviorScript.data;
// Use behavior data
enemy.setBehavior(goblinBehavior);// Load utils
const utilsScript = await scriptManager.loadScript('core', 'utils.js');
const { distance3D, lerp, randomInt } = utilsScript.data;
// Use utilities
const dist = distance3D(player.position, enemy.position);
const interpolated = lerp(0, 100, 0.5);
const random = randomInt(1, 10);// Reload a script after editing
await scriptManager.reloadScript('abilities/warrior/slash.js');Please share your C# scripts or any other scripts you have, and I can:
- ✅ Convert C# to JavaScript
- ✅ Create equivalent Lua scripts
- ✅ Design JSON behavior trees
- ✅ Integrate them into the system
# For Lua scripting support
npm install fengari fengari-web
# For better development experience
npm install --save-dev vite// In your game initialization code
import { scriptManager } from './src/scripting/ScriptManager.js';
async function initGame() {
// Initialize script manager
await scriptManager.init({ hotReload: true });
// Load core scripts
const utils = await scriptManager.loadScript('core', 'utils.js');
const constants = await scriptManager.loadScript('core', 'constants.js');
console.log('✅ Scripting system ready!');
}Follow the examples in:
assets/util/scripts/abilities/warrior/slash.js- Ability exampleassets/util/scripts/behaviors/enemy/goblin.json- AI exampleassets/util/scripts/core/utils.js- Utility functions
assets/util/scripts/README.md- Script directory guidedocs/SCRIPTING_SYSTEM_GUIDE.md- Complete scripting guidesrc/scripting/ScriptManager.js- ScriptManager implementation- This file - Setup summary
I'm ready to:
- ✅ Convert your C# scripts to JavaScript
- ✅ Create custom abilities, behaviors, or systems
- ✅ Set up Lua scripting if needed
- ✅ Design behavior trees for AI
- ✅ Fix any scripting issues
Please share your scripts and let me know what you'd like to do with them!
public class PlayerController : MonoBehaviour {
public float speed = 5f;
void Update() {
float h = Input.GetAxis("Horizontal");
float v = Input.GetAxis("Vertical");
transform.position += new Vector3(h, 0, v) * speed * Time.deltaTime;
}
}export class PlayerController {
constructor(mesh, scene) {
this.mesh = mesh;
this.scene = scene;
this.speed = 5;
}
update(deltaTime) {
const inputMap = this.scene.inputMap;
const h = (inputMap['d'] ? 1 : 0) - (inputMap['a'] ? 1 : 0);
const v = (inputMap['w'] ? 1 : 0) - (inputMap['s'] ? 1 : 0);
this.mesh.position.x += h * this.speed * deltaTime;
this.mesh.position.z += v * this.speed * deltaTime;
}
}Ready when you are! Share your scripts and let's get them working in your game! 🚀