fix mal de mer
This commit is contained in:
parent
ba41eb9893
commit
2d12cf2a47
61
main.js
61
main.js
@ -122,7 +122,7 @@ for (let i = 0; i < maze.count; i++) {
|
|||||||
const clone = invisibleWall.clone()
|
const clone = invisibleWall.clone()
|
||||||
clone.position.setFromMatrixPosition(matrix);
|
clone.position.setFromMatrixPosition(matrix);
|
||||||
clone.position.y = 1;
|
clone.position.y = 1;
|
||||||
collisionner.add(clone);
|
//collisionner.add(clone);
|
||||||
}
|
}
|
||||||
|
|
||||||
// Ground
|
// Ground
|
||||||
@ -165,12 +165,17 @@ const groundMaterial = new THREE.MeshStandardMaterial({
|
|||||||
}
|
}
|
||||||
),
|
),
|
||||||
})
|
})
|
||||||
const sideGroundMaterial = groundMaterial.clone()
|
|
||||||
sideGroundMaterial.map = wallMaterial.map.clone()
|
const sideGroundMaterial = new THREE.MeshStandardMaterial({
|
||||||
sideGroundMaterial.normalMap = wallMaterial.normalMap.clone()
|
map : wallMaterial.map.clone(),
|
||||||
sideGroundMaterial.metalnessMap = wallMaterial.metalnessMap.clone()
|
normalMap : wallMaterial.normalMap.clone(),
|
||||||
sideGroundMaterial.roughnessMap = wallMaterial.roughnessMap.clone()
|
normalScale : new THREE.Vector2(0.6, 0.6),
|
||||||
sideGroundMaterial.aoMap = wallMaterial.aoMap.clone()
|
metalnessMap: wallMaterial.metalnessMap.clone(),
|
||||||
|
aoMap : wallMaterial.aoMap.clone(),
|
||||||
|
roughnessMap: wallMaterial.roughnessMap.clone(),
|
||||||
|
roughness : 1,
|
||||||
|
envMapIntensity: 0.4
|
||||||
|
})
|
||||||
sideGroundMaterial.map.wrapS = sideGroundMaterial.map.wrapT = THREE.RepeatWrapping
|
sideGroundMaterial.map.wrapS = sideGroundMaterial.map.wrapT = THREE.RepeatWrapping
|
||||||
sideGroundMaterial.normalMap.wrapS = sideGroundMaterial.normalMap.wrapT = THREE.RepeatWrapping
|
sideGroundMaterial.normalMap.wrapS = sideGroundMaterial.normalMap.wrapT = THREE.RepeatWrapping
|
||||||
sideGroundMaterial.metalnessMap.wrapS = sideGroundMaterial.metalnessMap.wrapT = THREE.RepeatWrapping
|
sideGroundMaterial.metalnessMap.wrapS = sideGroundMaterial.metalnessMap.wrapT = THREE.RepeatWrapping
|
||||||
@ -201,6 +206,10 @@ ground.updateMatrix();
|
|||||||
|
|
||||||
collisionner.add(ground)
|
collisionner.add(ground)
|
||||||
|
|
||||||
|
scene.add(collisionner);
|
||||||
|
|
||||||
|
const mazeOctree = new Octree().fromGraphNode(collisionner);
|
||||||
|
|
||||||
// Water
|
// Water
|
||||||
|
|
||||||
const waterGeometry = new THREE.PlaneGeometry(1024, 1024, 512, 512);
|
const waterGeometry = new THREE.PlaneGeometry(1024, 1024, 512, 512);
|
||||||
@ -344,14 +353,8 @@ raft.position.set( .2, ocean.position.y, -mazeWidth/2 - 1 );
|
|||||||
raft.rotation.y = 1.4
|
raft.rotation.y = 1.4
|
||||||
raft.castShadow = true;
|
raft.castShadow = true;
|
||||||
|
|
||||||
collisionner.add(raft);
|
scene.add(raft);
|
||||||
const raftOctree = new Octree();
|
const raftOctree = new Octree().fromGraphNode(raft);
|
||||||
raftOctree.fromGraphNode(raft)
|
|
||||||
|
|
||||||
scene.add(collisionner);
|
|
||||||
|
|
||||||
const worldOctree = new Octree();
|
|
||||||
worldOctree.fromGraphNode(collisionner);
|
|
||||||
|
|
||||||
//
|
//
|
||||||
|
|
||||||
@ -368,7 +371,7 @@ if (showParam) {
|
|||||||
lightHelper.position.copy(maze.start)
|
lightHelper.position.copy(maze.start)
|
||||||
lightHelper.visible = false;
|
lightHelper.visible = false;
|
||||||
|
|
||||||
const octreeHelper = new OctreeHelper(worldOctree);
|
const octreeHelper = new OctreeHelper(mazeOctree);
|
||||||
octreeHelper.visible = false;
|
octreeHelper.visible = false;
|
||||||
scene.add(octreeHelper);
|
scene.add(octreeHelper);
|
||||||
const showHelper = gui.add({ helpers: false }, "helpers")
|
const showHelper = gui.add({ helpers: false }, "helpers")
|
||||||
@ -546,19 +549,14 @@ document.addEventListener('keyup', (event) => {
|
|||||||
|
|
||||||
function playerCollisions() {
|
function playerCollisions() {
|
||||||
|
|
||||||
if (raftOctree.capsuleIntersect(playerCollider)) {
|
const playerOnMaze = mazeOctree.capsuleIntersect(playerCollider);
|
||||||
|
const playerOnRaft = raftOctree.capsuleIntersect(playerCollider);
|
||||||
|
|
||||||
camera.position.y = raft.position.y + 0.9;
|
const result = playerOnMaze || playerOnRaft;
|
||||||
|
|
||||||
if (!escaped) gameEnd()
|
|
||||||
|
|
||||||
}
|
|
||||||
|
|
||||||
const result = worldOctree.capsuleIntersect(playerCollider);
|
|
||||||
|
|
||||||
playerOnFloor = false;
|
playerOnFloor = false;
|
||||||
|
|
||||||
if (result) {
|
if ( result ) {
|
||||||
|
|
||||||
playerOnFloor = result.normal.y > 0;
|
playerOnFloor = result.normal.y > 0;
|
||||||
|
|
||||||
@ -572,6 +570,14 @@ function playerCollisions() {
|
|||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if (playerOnRaft) {
|
||||||
|
|
||||||
|
camera.position.y = raft.position.y + 0.9;
|
||||||
|
|
||||||
|
if (!escaped) gameEnd()
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
function gameEnd() {
|
function gameEnd() {
|
||||||
@ -604,10 +610,10 @@ function updatePlayer(deltaTime) {
|
|||||||
const deltaPosition = playerVelocity.clone().multiplyScalar(deltaTime);
|
const deltaPosition = playerVelocity.clone().multiplyScalar(deltaTime);
|
||||||
playerCollider.translate(deltaPosition);
|
playerCollider.translate(deltaPosition);
|
||||||
|
|
||||||
playerCollisions();
|
|
||||||
|
|
||||||
camera.position.copy(playerCollider.end);
|
camera.position.copy(playerCollider.end);
|
||||||
|
|
||||||
|
playerCollisions();
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
function getForwardVector() {
|
function getForwardVector() {
|
||||||
@ -763,6 +769,7 @@ function animate() {
|
|||||||
const deltaTime = delta / STEPS_PER_FRAME;
|
const deltaTime = delta / STEPS_PER_FRAME;
|
||||||
|
|
||||||
ocean.material.uniforms['time'].value += delta;
|
ocean.material.uniforms['time'].value += delta;
|
||||||
|
|
||||||
updateRaft(delta);
|
updateRaft(delta);
|
||||||
|
|
||||||
// we look for collisions in substeps to mitigate the risk of
|
// we look for collisions in substeps to mitigate the risk of
|
||||||
|
Loading…
x
Reference in New Issue
Block a user