Added Freecam + Player is now aligned with ground

This commit is contained in:
2023-11-12 17:03:40 +01:00
parent 4abf0da9d2
commit 214ab7e363
3 changed files with 37 additions and 6 deletions

9
src/utils/placement.js Normal file
View File

@@ -0,0 +1,9 @@
import * as THREE from 'three';
export function alignGround(ground, MovingObject){
const boundingBoxGround = new THREE.Box3().setFromObject(ground);
const boundingBoxMovingObject = new THREE.Box3().setFromObject(MovingObject);
const MovingObjectHeight = boundingBoxMovingObject.max.z - boundingBoxMovingObject.min.z;
MovingObject.position.y = MovingObjectHeight/2 + boundingBoxGround.max.z;
}