8000 Describe the bug · Issue #25 · yomotsu/meshwalk · GitHub
[go: up one dir, main page]
More Web Proxy on the site http://driver.im/
Skip to content

Describe the bug #25

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
Jinxishihenian opened this issue Jun 12, 2024 · 2 comments
Open

Describe the bug #25

Jinxishihenian opened this issue Jun 12, 2024 · 2 comments

Comments

@Jinxishihenian
Copy link

Collision detection anomalies

1.When initialized, it cannot be moved when the moving object is larger than other objects.
2.When a moving object jumps, it can overlap with other objects.

<script type="module">
import * as THREE from 'three';
import * as MW from '../dist/meshwalk.module.js';
// See demo/2_keyboardInput.html first

const world = new MW.World();
const octree = new MW.Octree();
world.add( octree );


const width = window.innerWidth;
const height = window.innerHeight;
const clock = new THREE.Clock();
const scene = new THREE.Scene();
const camera = new THREE.PerspectiveCamera( 40, width / height, 1, 1000 );
camera.position.set( 0, 0, 8 );
const renderer = new THREE.WebGLRenderer();
renderer.setSize( width, height );
document.body.appendChild( renderer.domElement );


const ground = new THREE.Mesh(
	new THREE.PlaneGeometry( 30, 30, 10, 10 ),
	new THREE.MeshBasicMaterial( { color: 0xffffff,  wireframe: true } )
);
ground.rotation.x = - 90 * THREE.MathUtils.DEG2RAD;
scene.add( ground );
octree.addGraphNode( ground );


const wall = new THREE.Mesh(
	new THREE.BoxGeometry( .5, .5, .5 ),
	new THREE.MeshNormalMaterial( { wireframe: true } )
);
wall.position.set( 0, .5, 0 );
scene.add( wall );
octree.addGraphNode( wall );

const playerRadius = .75;
const playerObjectHolder = new THREE.Object3D();
scene.add( playerObjectHolder );

const sphere = new THREE.Mesh(
	new THREE.SphereGeometry( playerRadius, 16, 16 ),
	new THREE.MeshBasicMaterial( { color: 0xff0000,  wireframe: true} )
);
sphere.position.y = playerRadius;
playerObjectHolder.add( sphere );

const playerController = new MW.CharacterController( playerObjectHolder, playerRadius );
playerController.teleport( 0, 10, 0 );
world.add( playerController );

const keyInputControl = new MW.KeyInputControl();

const tpsCameraControls = new MW.TPSCameraControls(
	camera, // three.js camera
	playerObjectHolder, // tracking object
	world,
	renderer.domElement
);


// bind events
keyInputControl.addEventListener( 'movekeyon',    () => playerController.isRunning = true );
keyInputControl.addEventListener( 'movekeyoff',   () => playerController.isRunning = false );
keyInputControl.addEventListener( 'jumpkeypress', () => playerController.jump() );

// synk with keybord input and camera control input
keyInputControl.addEventListener( 'movekeychange', () => {

	const cameraFrontAngle    = tpsCameraControls.frontAngle;
	const characterFrontAngle = keyInputControl.frontAngle;
	playerController.direction = cameraFrontAngle + characterFrontAngle;

} );

// the 'updated' event is fired by `tpsCameraControls.update()`
tpsCameraControls.addEventListener( 'update', () => {

	if ( ! playerController.isRunning ) return;

	const cameraFrontAngle = tpsCameraControls.frontAngle;
	const characterFrontAngle = keyInputControl.frontAngle;
	playerController.direction = cameraFrontAngle + characterFrontAngle;

} );


( function update () {

	const delta = clock.getDelta();

	requestAnimationFrame( update );
	world.fixedUpdate();
	tpsCameraControls.update( delta );
	renderer.render( scene, camera );

} )();
</script>

Snipaste_2024-06-12_11-24-39

4

@Jinxishihenian
Copy link
Author

I guess it may be the problem caused by taking a collision using radiographic detection.

@Jinxishihenian
Copy link
Author

https://threejs.org/examples/?q=games#games_fps
I noticed that this example also uses an octree for collision detection, and the effect is excellent, and I have found no problems so far, I don't know if it helps this bug.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant
0