Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- import * as THREE from './three.module.js';
- import HumanInterfaceDevice from './humaninterfacedevice.js';
- import { CrossProduct } from './crossproduct.js';
- class collisionChecker {
- constructor(scene, camera, segments, hid) {
- this.scene = scene;
- this.camera = camera;
- this.segments = segments;
- this.hid = hid;
- this.check();
- }
- check() {
- this.segments.forEach(element => {
- this.detect(element.position);
- });
- }
- detect(elem) {
- // Speed might jump the distanceThreshold ** CAUTION **
- this.hid.speed = 155;
- var x = this.hid.direction.x;
- var z = this.hid.direction.z;
- var velX = this.hid.velocity.x;
- var velZ = this.hid.velocity.z;
- var cgX = this.hid.controls.x;
- var cgZ = this.hid.controls.z;
- const directs = [ this.hid.moveForward, this.hid.moveBackward, this.hid.moveLeft, this.hid.moveRight ];
- if ((cgX || cgZ) && directs.indexOf(1) == -1) return;
- this.hid.controls.x = (Math.round(cgX) >= Math.round(elem.x) && Math.round(cgX) < elem.width) ? 0 : (Math.round(cgZ * cgX) / 2 >= Math.round(elem.x) && Math.round(cgZ * cgX) / 2 < elem.width) ? 0 : (cgX + velX) * (-z);
- this.hid.controls.z = (Math.round(cgZ) >= Math.round(elem.z) && Math.round(cgZ) < elem.depth) ? 0 : (Math.round(cgX * cgZ) / 2 >= Math.round(elem.z) && Math.round(cgZ * cgX) / 2 < elem.depth) ? 0 : (cgZ + velZ) * (-x);
- const delta = this.hid.clock.getDelta();
- this.hid.update(delta);
- }
- }
- export { collisionChecker };
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement