Currently, I am working on a project that involves getting a player to move around a 3D house environment. While I have successfully loaded the house using obj and mtl loaders, as well as implemented player controls for moving forward and backward, I am encountering an issue with the player's movement on stairs. The player is unable to navigate up or down the stairs in the house. In my code, I have utilized point_lock_controls and raycaster for this functionality. If anyone can provide insight into where I may have gone wrong, it would be greatly appreciated.
controls = new THREE.PointerLockControls( camera );
scene.add( controls.getObject() );
// Event listeners for key presses
var onKeyDown = function ( event ) {
// Handle key-down events
};
var onKeyUp = function ( event ) {
// Handle key-up events
};
document.addEventListener( 'keydown', onKeyDown, false );
document.addEventListener( 'keyup', onKeyUp, false );
raycaster = new THREE.Raycaster( new THREE.Vector3(), new THREE.Vector3( 0, -1, 0 ), 0, 10 );
// Animation loop
function animate() {
requestAnimationFrame( animate );
// Update player movement based on controls
}
I looked into using the FPS example provided at this link, which uses a JSON loader. Since I am using OBJ and MTL loaders, I attempted to modify the code to suit my needs. However, I have run into issues where the player model falls through the floor and an error message "THREE.Object3D.add: object not an instance of THREE.Object3D" is displayed. Any assistance in rectifying this code reference error would be highly valued.
My specific query pertains to how I can incorporate OBJ and MTL loaders into the aforementioned example to load my custom model while enabling player movement. The following code snippet showcases the modifications I made to integrate these loaders:
// Function to create platform with custom model
function makePlatform() {
// Code for loading and positioning the custom model
}
// Additional setup for renderer, camera, lighting, etc.