fenomas / noa

Experimental voxel game engine.
MIT License
616 stars 91 forks source link

Way to customize what block IDs are affected by raycasts and targeting #36

Closed fenomas closed 6 years ago

fenomas commented 6 years ago

Let the client specify which block IDs are considered targets of raycasts (noa.pick) and auto block targeting.

fenomas commented 6 years ago

Done in b6fefc94c218f62e3b239c838b2e8ab4ba33b0f7

@terrac Hey, please check this in the dev branch if you can, it should address what you asked about for making it possible to target water blocks.

Usage is, you define a function that takes a block ID and returns true/false, and then either pass that function to the raycast method (noa.pick) or set it to be the block highlighting function.

// to target solid blocks and also water
function solidOrWater(id) {
    if (id === waterBlockID) return true
    return noa.registry.getBlockSolidity(id)
}

// to use this function for default block highlighting
noa.blockTargetIdCheck = solidOrWater

// to raycast with this function
var result = noa.pick(pos, dir, distance, solidOrWater)
fenomas commented 6 years ago

Closing this, please reopen if the fix doesn't work for you.