Skip to content

Commit

Permalink
raycastVoxels() default normal to top face if hits inside voxel
Browse files Browse the repository at this point in the history
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.
  • Loading branch information
deathcap committed Mar 29, 2015
1 parent 6b5c953 commit fb84427
Showing 1 changed file with 6 additions and 0 deletions.
6 changes: 6 additions & 0 deletions index.js
Original file line number Diff line number Diff line change
Expand Up @@ -280,6 +280,12 @@ Game.prototype.raycastVoxels = function(start, direction, maxDistance, epilson)
var adjacentPosition = [0, 0, 0]
var voxelPosition = this.voxelPosition(hitPosition)
vector.add(adjacentPosition, voxelPosition, hitNormal)

if (hitNormal[0] + hitNormal[1] + hitNormal[2] !== 1) {
hitNormal[0] = 0
hitNormal[1] = 1
hitNormal[2] = 0
}

return {
position: hitPosition,
Expand Down

0 comments on commit fb84427

Please sign in to comment.