{"id":15722577,"url":"https://github.com/selimanac/defold-tile-raycast","last_synced_at":"2025-10-30T08:03:09.936Z","repository":{"id":152789742,"uuid":"554281491","full_name":"selimanac/defold-tile-raycast","owner":"selimanac","description":"Ray Casting in tiled worlds using DDA algorithm.","archived":false,"fork":false,"pushed_at":"2022-10-24T16:02:59.000Z","size":862,"stargazers_count":16,"open_issues_count":0,"forks_count":0,"subscribers_count":1,"default_branch":"master","last_synced_at":"2025-04-20T23:32:29.649Z","etag":null,"topics":["defold","defold-engine","defold-game-engine","defold-library","defold-native-extension","game-development","gamedev"],"latest_commit_sha":null,"homepage":"","language":"Lua","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"mit","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/selimanac.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":".github/FUNDING.yml","license":"LICENSE.md","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null},"funding":{"github":"selimanac"}},"created_at":"2022-10-19T14:49:39.000Z","updated_at":"2025-04-07T16:14:08.000Z","dependencies_parsed_at":null,"dependency_job_id":"76ade629-b485-4deb-b97d-96bf097605e9","html_url":"https://github.com/selimanac/defold-tile-raycast","commit_stats":null,"previous_names":[],"tags_count":0,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/selimanac%2Fdefold-tile-raycast","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/selimanac%2Fdefold-tile-raycast/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/selimanac%2Fdefold-tile-raycast/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/selimanac%2Fdefold-tile-raycast/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/selimanac","download_url":"https://codeload.github.com/selimanac/defold-tile-raycast/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":253922493,"owners_count":21984730,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["defold","defold-engine","defold-game-engine","defold-library","defold-native-extension","game-development","gamedev"],"created_at":"2024-10-03T22:08:28.319Z","updated_at":"2025-10-30T08:03:09.931Z","avatar_url":"https://github.com/selimanac.png","language":"Lua","funding_links":["https://github.com/sponsors/selimanac"],"categories":["Libraries"],"sub_categories":["Programming Language"],"readme":"![Tile Raycast](/.github/tile_raycast_2400x666.png)\n\n# Tile Raycast\nRaycasting in tiled worlds using the DDA algorithm. It is a very effective solution for tile-based worlds such as platformers or top-down games.    \n\nThis implementation is inspired by:  \nhttps://lodev.org/cgtutor/raycasting.html  \nhttps://www.youtube.com/watch?v=NbSee-XM7WA  \n\n# Installation\n\nYou can use Tiled Raycast in your own project by adding this project as a [Defold library dependency](http://www.defold.com/manuals/libraries/). Open your `game.project` file and in the `dependencies` field under `project`, add:\n\nhttps://github.com/selimanac/defold-tile-raycast/archive/refs/heads/master.zip\n\n\n# Examples\n\nYou can find vision cone and line of sight examples in this project.   \nTest it here: https://selimanac.github.io/defold-tile-raycast/ \n\nFor v1: https://github.com/selimanac/defold-tile-raycast-platformer  \n\n# Release Notes\n### v2\n- **BREAKING:** Module name has been changed to `tile_raycast`\n- Complete code refactoring\n- Performance improvements\n- New vision cone and line of sight examples\n\n# Use Cases(AI Generated)\n\n### Ray Casting in Games\n\n2D Top-Down Roguelikes: Games like \"The Binding of Isaac\" and \"Enter the Gungeon\" use ray casting for line-of-sight calculations, bullet trajectory.  \n\nWolfenstein 3D and similar pseudo-3D engines: The original Wolfenstein 3D used DDA-based ray casting to create a 3D-like environment from a 2D map.  \n\nMinecraft uses a variation for block targeting and lighting calculations.  \n\n### Line-of-Sight Systems\n\nTactical games like \"XCOM\" and \"Into the Breach\" use DDA for determining visibility between units.  \n\nStealth games for guard vision cones and detection systems.  \n\n### Procedural Generation\n\nDungeon crawlers like \"Rogue Legacy\" use it for connecting rooms and ensuring paths are traversable.  \n\nSpelunky and similar games for procedural level interconnections.  \n\n### Other Applications\n\nTower defense games for targeting and projectile calculations.  \n\nStrategy games for unit visibility and pathing calculations. \n\nBattle royale games for circle/zone damage calculations across grid terrain.  \n\n\n# API\n\n### tile_raycast.setup(`tile_width`, `tile_heigh`,`tilemap_width`,`tilemap_height`,`tiles`,`target_tiles`)\n\nInitial setup for raycasting.  \n\n**PARAMETERS**\n* `tile_width` (uint16_t) – Width of a single tile.\n* `tile_height` (uint16_t) – Height of a single tile.\n* `tilemap_width` (uint16_t) – Number of tiles horizontally in the tilemap.\n* `tilemap_height` (uint16_t) – Number of tiles vertically in the tilemap.\n* `tiles` (table - uint16_t ) – One-dimensional tile table generated from your tilemap or source data.\n* `target_tiles` (table - uint16_t) – IDs of impassable tiles from your tilesource (e.g., walls, ground, etc.).\n\n**EXAMPLE**\n```lua\n\t\n    local tiles = {\n\t\t4,2,2,2,0,2,2,2,2,2,\n\t\t2,2,2,2,0,2,2,2,2,2,\n\t\t2,2,2,2,0,2,2,2,2,2,\n\t\t2,2,1,2,2,2,2,2,2,2,\n\t\t2,2,2,2,2,2,2,2,2,2,\n\t\t1,2,1,2,2,2,1,1,1,1,\n\t\t1,1,1,2,2,2,1,1,1,1,\n\t\t1,1,1,2,1,2,1,3,1,1,\n\t\t1,1,1,1,2,1,1,1,4,1,\n\t\t1,1,1,2,2,2,2,1,1,3,\n        1,1,1,1,1,1,1,1,1,1  \n\t}\n\n    local tile_width = 32\n    local tile_height = 32\n    local target_tiles = {2, 3, 4}\n    local tilemap_width = 10\n    local tilemap_height = 11\n\n    tile_raycast.setup(tile_width, tile_height, tilemap_width, tilemap_height, tiles, target_tiles)\n``` \n\n---\n\n### tile_raycast.cast(`ray_from_x`,`ray_from_y`,`ray_to_x`, `ray_to_y`)\n\nPerforms a raycast on the tilemap. Returns **only the first** successful hit.\n\n**PARAMETERS**\n* `ray_from_x` (float) – Start position of the ray (X).\n* `ray_from_y` (float) – Start position of the ray (Y).\n* `ray_to_x` (float) – End position of the ray (X).\n* `ray_to_y` (float) – End position of the ray (Y).\n\n**RETURN**\n* `hit` (boolean) – Whether a tile was hit.\n* `tile_x` (uint16_t) – X position of the tile.\n* `tile_y` (uint16_t) – Y position of the tile.\n* `array_id` (uint16_t) – Index in the tilemap array.\n* `tile_id` (uint16_t) – ID of the tile from the tilesource.\n* `intersection_x` (float) – X coordinate of the ray intersection point.\n* `intersection_y` (float) – Y coordinate of the ray intersection point.\n* `side` (enum) – The side of the tile that was hit.\n\n   **tile_raycast.LEFT**   \n   **tile_raycast.RIGHT**   \n   **tile_raycast.TOP**   \n   **tile_raycast.BOTTOM**   \n\n\n\n**EXAMPLE**\n```lua\n\t\n    local ray_from = go.get_position(ray_start_url)\n    local ray_to = go.get_position(ray_end_url)\n\n    local hit, tile_x, tile_y, array_id, tile_id, intersection_x, intersection_y, side = tile_raycast.cast(ray_from.x,ray_from.y, ray_to.x,ray_to.y)\n\n     if hit then\n        print(\"tile_x: \" .. tile_x)\n        print(\"tile_y: \" .. tile_y)\n        print(\"array_id \" .. array_id)\n        print(\"tile_id \" .. tile_id)\n        print(\"intersection_x \" .. intersection_x)\n        print(\"intersection_y \" .. intersection_y)\n        print(\"Side \" .. side) \n    else\n        print(\"No result found\")\n    end\n``` \n\n---\n\n### tile_raycast.set_at(`tile_x`, `tile_y`, `tile_id`)\n\nSets a tile value in the map array at the specified coordinates.\n\n**PARAMETERS**\n* `tile_x` (uint16_t) – Tile X coordinate.\n* `tile_y` (uint16_t) – Tile Y coordinate.\n* `tile_id` (uint16_t) – Tile ID to set.\n\n---\n\n### tile_raycast.get_at(`tile_x`, `tile_y`)\n\nReturns the tile ID from the map array at the specified coordinates.\n\n**PARAMETERS**\n* `tile_x` (uint16_t) – Tile X coordinate.\n* `tile_y` (uint16_t) – Tile Y coordinate.\n\n**RETURN**\n* `tile_id` (uint16_t) – Tile ID at the given coordinates.\n\n---\n\n\n### tile_raycast.reset()\n\nClears all tile and tilemap data.\n\n\n\n\n\n\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fselimanac%2Fdefold-tile-raycast","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fselimanac%2Fdefold-tile-raycast","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fselimanac%2Fdefold-tile-raycast/lists"}