-
Notifications
You must be signed in to change notification settings - Fork 219
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Right Mouse button #114
Comments
Sorry I'm kinda new to this, could you please provide a short example? I managed to get this working with gamejs but that is giving me a few annoying bugs |
This is how I managed to get it working now. // Controls
controls()
function controls(){
//Mouse Input
document.body.addEventListener('mousedown', mousePressed)
function mousePressed(event){
switch(event.button){
case 0: // Left mouse button
var position = block
if(game.getBlock(position) != 0){
game.setBlock(position, 0)
console.log('Break: ' + position)
} else{
console.log('No Block')
}
break;
case 1: // Middle mouse button
var position = block
var type = game.getBlock(position)
console.log('BlockType: ' + type + ' : ' + position)
break;
case 2: // Right mouse button
console.log(adjacentBlock)
var position = adjacentBlock
console.log(position)
game.setBlock(position, 1)
console.log('Placed: ' + position)
}
}
} |
Ah sorry I didn't understand your original request. Here is an example which raycasts from the player's position and vector to determine the block to set (in which function raycast(dist) {
dist = dist || 100
var pos = game.cameraPosition()
var vec = game.cameraVector()
return game.raycastVoxels(pos, vec, dist)
}
document.addEventListener('mousedown', function(e) {
if (e.button === 2) {
var block = raycast()
if (block) game.setBlock(block.position, 1)
}
}) Also check out https://github.com/maxogden/voxel-highlight which does this and https://github.com/maxogden/voxel-hello-world/blob/master/index.js for a more in depth example. |
Thanks! I am currently using this. hl.on('highlight-adjacent', function(voxelPos) {
adjacentBlock = voxelPos
game.setBlock(adjacentBlock, 1)
console.log('Placed: ' + adjacentBlock)
}); |
I was thinking of making some sort of wiki for voxel-engine and similar packages where we can put important things like this, what do you think? Also, is voxel-hello-world broken? |
You'd want to talk to @kumavis (as I think he is primary maintainer now?) I'm not up to date on the current status of all the voxel- projects. I know a great deal of the effort has been move towards http://stack.gl/ and I think the plan is to circle back to the voxel- projects once the resources there are sufficient. |
@shama That sounds interesting, but as I understand it voxel-engine uses Three.js right? So wouldn't that require rewriting it in stack.gl? |
@z3t0 I don't think any parts of three.js need to be rewritten. We just write the modules we need and try to avoid creating too much interdependence (as that would give us the same issues we have with three.js now). A lot of these modules (or at least the foundation) already exist:
It's a bit all over the place atm but the holes are slowly being filled in. Once they are, making voxel modules and apps will become much easier and we'll be able to do a lot more interesting work. |
The biggest missing piece in the ndarray/stackgl branch (#103) right now is player avatars, there isn't anything like we had in three.js ported over, afaik. For the original question of detecting right-click, #112 has some relevant pointers. I use https://github.com/deathcap/voxel-reach to handle DOM mousedown events; https://github.com/mikolalysenko/game-shell also listens for this event and provides a polling-style interface, which I use via descriptive keybinding names in https://github.com/deathcap/voxel-keys - this plugin also handles preventing the "default" browser action for both keys and mouse actions, so you can use them uninterrupted in your game (that is, it listens for DOM keydown and contextmenu events and calls |
@deathcap @shama Thanks for the informative replies! We should probably create some sort of overarching wiki for the whole voxel-* project(s) because things like this are really confusing when you first start out. P.S: This might be kinda stupid but... Is there some wiki out there I am not aware of? Because that would help a lot 😄. Otherwise I could work on building the skeleton for one and you guys could fill in the technical details? |
There seems to be no way to detect the right mouse button..
The text was updated successfully, but these errors were encountered: