Skip to content

Commit fb84427

Browse files
committed
raycastVoxels() default normal to top face if hits inside voxel
voxel-raycast can return a hit normal of [0,0,0] if, for example, the starting position is within a voxel, but this is not a valid normal vector. If this happens, instead default to [0,1,0], the top face.
1 parent 6b5c953 commit fb84427

File tree

1 file changed

+6
-0
lines changed

1 file changed

+6
-0
lines changed

index.js

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -280,6 +280,12 @@ Game.prototype.raycastVoxels = function(start, direction, maxDistance, epilson)
280280
var adjacentPosition = [0, 0, 0]
281281
var voxelPosition = this.voxelPosition(hitPosition)
282282
vector.add(adjacentPosition, voxelPosition, hitNormal)
283+
284+
if (hitNormal[0] + hitNormal[1] + hitNormal[2] !== 1) {
285+
hitNormal[0] = 0
286+
hitNormal[1] = 1
287+
hitNormal[2] = 0
288+
}
283289

284290
return {
285291
position: hitPosition,

0 commit comments

Comments
 (0)