
Product
Announcing Bun and vlt Support in Socket
Bringing supply chain security to the next generation of JavaScript package managers
raycast-2d-tilemap
Advanced tools
Test a ray for intersections against a 2D tile map.
This module is built atop the excellent fast-voxel-raycast by Andy Hall, which in turn is a fork of Mikola Lysenko's wonderful voxel-raycast.
Both are 3D voxel modules -- this module just wraps Andy's work to provide a clean 2D interface.
npm install raycast-2d-tilemap
var raycast = require('raycast-2d-tilemap')
var tilemap = [
[ 0, 0, 0, 1 ],
[ 1, 0, 0, 1 ],
[ 1, 0, 0, 1 ],
[ 1, 1, 1, 1 ]
]
function getTileAt(x, y) {
return tilemap[y][x]
}
var rayStart = [1, 0]
var rayDir = [0, 1]
var maxDistance = 100
var hitPos = new Array(2)
var hitNormal = new Array(2)
var tile = raycast(getTileAt, rayStart, rayDir, maxDistance, hitPos, hitNormal)
console.log(hitPos)
console.log(hitNormal)
outputs
[ 1, 3 ]
[ 0, -1 ]
var raycast = require('raycast-2d-tilemap')
getTileAt - a function(x, y) that returns a truthy value for whether a
tile should block the ray's pathrayStart - origin of the ray (vec2)rayDirection - direction of the ray (vec2)maxDistance - how far to check the ray before giving uphitPosition - result vec2 array; populated with the point of impacthitNormal - result vec2 array; populated with a normal vector pointing away
from the tile that was struckReturns: whatever value was returned by the getTileAt function for the
struck tile, or 0 if no tile was struck.
FAQs
test a 2d ray against a generic 2d grid of tiles
We found that raycast-2d-tilemap demonstrated a not healthy version release cadence and project activity because the last version was released a year ago. It has 1 open source maintainer collaborating on the project.
Did you know?

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Product
Bringing supply chain security to the next generation of JavaScript package managers

Product
A safer, faster way to eliminate vulnerabilities without updating dependencies

Product
Reachability analysis for Ruby is now in beta, helping teams identify which vulnerabilities are truly exploitable in their applications.