Skip to content

Add runtime-generated collision models from Lua - #5264

Open
Dryxio wants to merge 1 commit into
multitheftauto:masterfrom
Dryxio:runtime-collision-data
Open

Add runtime-generated collision models from Lua#5264
Dryxio wants to merge 1 commit into
multitheftauto:masterfrom
Dryxio:runtime-collision-data

Conversation

@Dryxio

@Dryxio Dryxio commented Aug 24, 2026

Copy link
Copy Markdown
Contributor

Summary

0817.1._10mb.mp4

Allow engineLoadCOL to create collision models directly from Lua tables containing spheres, boxes and triangle meshes.

local col = engineLoadCOL({
    boxes = {
        {
            position = { 0, 0, 0 },
            size = { 10, 1, 3 },
            material = 1
        }
    }
})

engineReplaceCOL(col, modelId)

Collision data can also be updated while the resource is running:

engineSetCOLData(col, newData)
-- or
col:setData(newData)

Models using the collision are updated immediately. Existing file and raw data support in engineLoadCOL remains unchanged.

The input is validated before being passed to GTA, including materials, coordinates, indices and native format limits.

Motivation

Resources currently need a pre-generated .col file to load custom collision.

Creating custom collision currently requires generating and shipping a separate .col file, even for a simple box or sphere.

This allows resources to define collision directly next to their Lua code. The same collision can also be updated at runtime when an object's size or shape changes.

The video uses the included test resource. It creates a wall, resizes its collision while running and turns the same collision into a ramp.

Test plan

Tested the included wall/ramp resource:

  1. Start runtime-collision-wall-demo
  2. Use /wall and place both endpoints
  3. Hold E to resize the wall
  4. Hold U to change its height
  5. Press P to turn it into a ramp
  6. Walk or drive into the generated collision

Note : This feature was originally implemented in my fork and has been tested with my community in various scenarios, the original documentation covers the table format, limits and live updates.

Test resource :
runtime-collision-wall-demo.zip

Checklist

  • Your code should follow the coding guidelines.
  • Smaller pull requests are easier to review. If your pull request is beefy, your pull request should be reviewable commit-by-commit.

Allow engineLoadCOL to accept tables of spheres, boxes, and mesh triangles, and add engineSetCOLData plus EngineCOL:setData for live updates.

Generate validated COL1 buffers client-side so resources can build procedural collision without temporary files. Preserve legacy file and raw-data loading, and repoint every replaced model before destroying the old collision to avoid dangling pointers.

Validate finite values, native counts, indices, materials, coordinate ranges, and repeated triangle vertices before passing data to GTA. Add serializer tests for valid output and malformed collision data.

Tested with Client Deathmatch Release|Win32, all 318 Tests_Client tests, and in-game create, live resize, wall, ramp, procedural, and OOP collision updates.
@Fernando-A-Rocha

Copy link
Copy Markdown
Contributor

Genius! ❤️‍🔥

@Fernando-A-Rocha

Copy link
Copy Markdown
Contributor
Games that become possible with this feature 😜
  1. Procedural Obstacle Course — Randomly generated platforms, walls, ramps and traps.

  2. Floor Is Lava — Random floor tiles lose collision; last player standing wins.

  3. Bridge Builder — Players construct physical bridges and test them with vehicles.

  4. Mario Maker GTA — Players build and share their own obstacle courses.

  5. Destructible Terrain — Explosions physically destroy/modify the terrain.

  6. Dynamic Tetris — Giant physical Tetris blocks fall and stack.

  7. Katamari GTA — A growing ball rolls over and collects objects.

  8. Multiplayer Snake — Physical snake bodies grow as players collect items.

  9. Dynamic Maze — Walls continuously move, disappear and regenerate.

  10. GTA Pac-Man — Procedurally generated collision maze with players as Pac-Man/ghosts.

  11. Troll Architect — One player dynamically creates obstacles while others try to finish.

  12. Glass Bridge — Only some randomly generated panels have collision.

  13. Infinite Procedural Road — Endless randomly generated driving track.

  14. Trackmania GTA — Procedurally generated racing tracks.

  15. Portal GTA — Dynamic portals and impossible geometry.

  16. Changing-Gravity Rooms — Floors/walls/ceilings dynamically become platforms.

  17. Monster Mode — One player becomes a giant physical monster that reshapes the map.

  18. Dynamic Battle Royale — Parts of the island physically disappear over time.

  19. Procedural Stunt Generator — Automatically generate ramps, loops, jumps and wallrides.

  20. Jenga with Cars — Players remove giant blocks by driving into them.

  21. Dynamic Car Soccer — Stadium geometry changes after every goal.

  22. Bridge Roulette — Random holes/obstacles appear in a bridge as players drive across.

  23. Human Pinball — Players bounce around a giant physical pinball machine.

  24. Physical Chess — Giant chess pieces that players physically push/capture.

  25. Survival Island — Procedurally generated islands that continuously reshape.

@FileEX FileEX added the enhancement New feature or request label Aug 24, 2026
@efejotaese2

Copy link
Copy Markdown
Contributor

that's insane.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

enhancement New feature or request

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants