UNPKG

@polygonjs/polygonjs

Version:

node-based WebGL 3D engine https://polygonjs.com

23 lines (22 loc) 807 B
"use strict"; import { Octree } from "../../../three/examples/jsm/math/Octree"; import { Capsule } from "../../../three/examples/jsm/math/Capsule"; import { Vector3 } from "three"; export class PlayerCollisionController { constructor(_object) { this._object = _object; this._octree = new Octree(); this._capsuleHeight = new Vector3(0, 1, 0); this._capsule = new Capsule(new Vector3(0, 0.35, 0), new Vector3(0, 1, 0), 0.6); this._octree.fromGraphNode(this._object); } setCapsule(capsule) { this._capsule.copy(capsule); this._capsuleHeight.copy(capsule.end).sub(capsule.start); } testPosition(position) { this._capsule.end.copy(position); this._capsule.start.copy(position).sub(this._capsuleHeight); return this._octree.capsuleIntersect(this._capsule); } }