UNPKG

@polygonjs/polygonjs

Version:

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

44 lines (43 loc) 2.02 kB
"use strict"; import { Vector3 } from "three"; import { CorePhysicsAttribute } from "../PhysicsAttribute"; const up = new Vector3(); export function createCharacterController(world, object) { const offset = CorePhysicsAttribute.getCharacterControllerOffset(object); const snapToGroundDistance = CorePhysicsAttribute.getCharacterControllerSnapToGroundDistance(object); const applyImpulsesToDynamic = CorePhysicsAttribute.getCharacterControllerApplyImpulsesToDynamic(object); const autoStepMaxHeight = CorePhysicsAttribute.getCharacterControllerAutoStepMaxHeight(object); const autoStepMinWidth = CorePhysicsAttribute.getCharacterControllerAutoStepMinWidth(object); const autoStepOnDynamic = CorePhysicsAttribute.getCharacterControllerAutoStepOnDynamic(object); CorePhysicsAttribute.getCharacterControllerUp(object, up); const maxSlopeClimbAngle = CorePhysicsAttribute.getCharacterControllerMaxSlopeClimbAngle(object); const minSlopeSlideAngle = CorePhysicsAttribute.getCharacterControllerMinSlopeSlideAngle(object); const characterController = world.createCharacterController(offset); console.log(offset, characterController); console.log({ offset, up, applyImpulsesToDynamic, snapToGroundDistance, autoStepMaxHeight, autoStepMinWidth, autoStepOnDynamic, maxSlopeClimbAngle, minSlopeSlideAngle }); characterController.setUp(up); characterController.setApplyImpulsesToDynamicBodies(applyImpulsesToDynamic); if (snapToGroundDistance) { characterController.enableSnapToGround(snapToGroundDistance); } else { characterController.disableSnapToGround(); } if (autoStepMaxHeight && autoStepMinWidth) { characterController.enableAutostep(autoStepMaxHeight, autoStepMinWidth, autoStepOnDynamic); } else { characterController.disableAutostep(); } characterController.setMaxSlopeClimbAngle(maxSlopeClimbAngle * Math.PI / 180); characterController.setMinSlopeSlideAngle(minSlopeSlideAngle * Math.PI / 180); return characterController; }