betterrer collisions
This commit is contained in:
parent
eb3ae6f00c
commit
4afc42ec2f
27
main.js
27
main.js
@ -74,8 +74,7 @@ const scene = new THREE.Scene();
|
|||||||
const camera = new THREE.PerspectiveCamera(70, window.innerWidth / window.innerHeight, 0.1, 1000);
|
const camera = new THREE.PerspectiveCamera(70, window.innerWidth / window.innerHeight, 0.1, 1000);
|
||||||
camera.rotation.order = 'YXZ';
|
camera.rotation.order = 'YXZ';
|
||||||
|
|
||||||
const worldOctree = new Octree();
|
const collisionner = new THREE.Group();
|
||||||
const raftOctree = new Octree();
|
|
||||||
|
|
||||||
// Maze
|
// Maze
|
||||||
|
|
||||||
@ -96,13 +95,14 @@ scene.add(maze)
|
|||||||
console.log(String(maze))
|
console.log(String(maze))
|
||||||
|
|
||||||
const invisibleWall = new THREE.Mesh(new THREE.BoxGeometry( .9, 1.8, .9 ));
|
const invisibleWall = new THREE.Mesh(new THREE.BoxGeometry( .9, 1.8, .9 ));
|
||||||
|
invisibleWall.material.visible = false;
|
||||||
let matrix = new THREE.Matrix4()
|
let matrix = new THREE.Matrix4()
|
||||||
for (let i = 0; i < maze.count; i++) {
|
for (let i = 0; i < maze.count; i++) {
|
||||||
maze.getMatrixAt(i, matrix)
|
maze.getMatrixAt(i, matrix)
|
||||||
const clone = invisibleWall.clone()
|
const clone = invisibleWall.clone()
|
||||||
clone.position.setFromMatrixPosition(matrix)
|
clone.position.setFromMatrixPosition(matrix);
|
||||||
clone.position.y += 0.5;
|
clone.position.y = 1;
|
||||||
worldOctree.fromGraphNode(clone)
|
collisionner.add(clone);
|
||||||
}
|
}
|
||||||
|
|
||||||
// Ground
|
// Ground
|
||||||
@ -178,9 +178,8 @@ ground.position.y = -0.5
|
|||||||
ground.receiveShadow = true;
|
ground.receiveShadow = true;
|
||||||
ground.matrixAutoUpdate = false
|
ground.matrixAutoUpdate = false
|
||||||
ground.updateMatrix();
|
ground.updateMatrix();
|
||||||
scene.add(ground)
|
|
||||||
|
|
||||||
worldOctree.fromGraphNode(ground)
|
collisionner.add(ground)
|
||||||
|
|
||||||
// Water
|
// Water
|
||||||
|
|
||||||
@ -342,10 +341,16 @@ const raft = new THREE.Mesh(raftGeometry, [
|
|||||||
raft.position.set( .2, ocean.position.y, -mazeWidth/2 - 1 );
|
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;
|
||||||
worldOctree.fromGraphNode(raft)
|
collisionner.add(raft);
|
||||||
|
const raftOctree = new Octree();
|
||||||
raftOctree.fromGraphNode(raft)
|
raftOctree.fromGraphNode(raft)
|
||||||
scene.add(raft)
|
scene.add(raft)
|
||||||
|
|
||||||
|
scene.add(collisionner);
|
||||||
|
|
||||||
|
const worldOctree = new Octree();
|
||||||
|
worldOctree.fromGraphNode(collisionner);
|
||||||
|
|
||||||
//
|
//
|
||||||
|
|
||||||
const stats = new Stats();
|
const stats = new Stats();
|
||||||
@ -368,7 +373,7 @@ if (showParam) {
|
|||||||
showHelper.onChange(function (value) {
|
showHelper.onChange(function (value) {
|
||||||
|
|
||||||
lightHelper.visible = value;
|
lightHelper.visible = value;
|
||||||
//octreeHelper.visible = value;
|
octreeHelper.visible = value;
|
||||||
|
|
||||||
});
|
});
|
||||||
|
|
||||||
@ -484,7 +489,7 @@ const clock = new THREE.Clock();
|
|||||||
|
|
||||||
const GRAVITY = 30;
|
const GRAVITY = 30;
|
||||||
|
|
||||||
const STEPS_PER_FRAME = 5;
|
const STEPS_PER_FRAME = 10;
|
||||||
|
|
||||||
const playerCollider = new Capsule(
|
const playerCollider = new Capsule(
|
||||||
new THREE.Vector3(0, 25.0, 0),
|
new THREE.Vector3(0, 25.0, 0),
|
||||||
@ -627,7 +632,7 @@ function getSideVector() {
|
|||||||
function controls(deltaTime) {
|
function controls(deltaTime) {
|
||||||
|
|
||||||
// gives a bit of air control
|
// gives a bit of air control
|
||||||
const speedDelta = deltaTime * (playerOnFloor ? 10 : 2);
|
const speedDelta = deltaTime * (playerOnFloor ? 100 : 20) / STEPS_PER_FRAME;
|
||||||
|
|
||||||
if (keyStates["ArrowUp"] || keyStates['KeyW']) {
|
if (keyStates["ArrowUp"] || keyStates['KeyW']) {
|
||||||
|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user