Skip to content
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

Collision physics for half-blocks or slabs #84

Open
ghost opened this issue Sep 13, 2019 · 7 comments
Open

Collision physics for half-blocks or slabs #84

ghost opened this issue Sep 13, 2019 · 7 comments

Comments

@ghost
Copy link

ghost commented Sep 13, 2019

Wanted to create a half block ,that’s easy but the problem is how can I stand on it , how can I implement collision detection on a half block so I can stand on it thanks Andy

@fenomas
Copy link
Owner

fenomas commented Sep 14, 2019

The short answer is this isn't in the engine yet.

Terrain physics is done in this library. It would be possible (but nontrivial) to add support for blocks with a collision volume smaller than the full voxel, but I haven't tried doing it.

@fenomas fenomas changed the title How to create a half block or slab Collision physics for half-blocks or slabs Jul 2, 2020
@Patbox
Copy link

Patbox commented Dec 14, 2020

I think I will try to experiment with it. My idea is to modify engine to output object with block's collision shape and using it for rest of checks. As I never did something similar before, do you have any suggestions/other ideas how it could work?

@ghost
Copy link
Author

ghost commented Dec 14, 2020

I think if you check when player inslab like in water and offset him

@ghost
Copy link
Author

ghost commented Dec 15, 2020

In physics.js
var createPhysics = require('voxel-physics-engine')
// var createPhysics = require('../../../../npm-modules/voxel-physics-engine')

export default function (noa, opts) {
return makePhysics(noa, opts)
}

/**

var defaults = {
gravity: [0, -10, 0],
airDrag: 0.1,
}

function makePhysics(noa, opts) {
opts = Object.assign({}, defaults, opts)
var world = noa.world
// physics engine runs in offset coords, so voxel getters need to match
var offset = noa.worldOriginOffset
var blockGetter = (x, y, z) => {
return world.getBlockSolidity(x + offset[0], y + offset[1], z + offset[2])
}
var isFluidGetter = (x, y, z) => {
return world.getBlockFluidity(x + offset[0], y + offset[1], z + offset[2])
}

var physics = createPhysics(opts, blockGetter, isFluidGetter)

return physics

}
...... You could a a new type like getblockfluidity , I tried that but on the physics library I was looking for 1.0 height to converted to 0.5 ,I couldn't figure it out

@fenomas
Copy link
Owner

fenomas commented Dec 15, 2020

@Patbox: I think the best approach would be to start with the dependency voxel-aabb-sweep. That library takes an AABB and a direction, and then "pushes" the AABB along that direction until it hits a solid voxel. Noa internally uses that dependency for both physics and for raycasting, so if voxel-aabb-sweep could handle partially-solid voxels then it should be relatively easy for noa.

Currently the voxel-aabb-sweep learns about collision geometry by way of a getVoxel function, which looks like (x,y,z) => boolean where the boolean means the voxel is solid or empty. If I was attacking this, I would try to make that function return, say, 0 for empty, 1 for full, and 2 for partial, and then when a partial voxel is encountered there would need to be a second function for the library to query that voxel's collision geometry.

But note that the math inside the "sweep" library is pretty complicated, and somewhat hard to test. Also I expect that it would be a lot easier if non-full voxels are required to have simple AABB collision geometries - i.e. things like half-slabs or fenceposts, but not slopes or arbitrary polygons.

@Heath123
Copy link
Contributor

If you don't need to sweep and just need to test overlaps then it's a lot easier, but that would probably be buggy

@ghost
Copy link
Author

ghost commented Dec 16, 2020

How would I overlap , explain me wath you know I almost cracked the code

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

3 participants