未验证 提交 d45c0e1b 编写于 作者: F Felix Mariotto 提交者: GitHub

fps example: collision detection in substeps (#21925)

* fps example: collision detection in substeps

* Update games_fps.html

Clean up.
Co-authored-by: NFelix Mariotto <felixmariotto@gmail.com>
Co-authored-by: NMichael Herzog <michael.herzog@human-interactive.org>
上级 4f4c845c
......@@ -77,6 +77,8 @@
const NUM_SPHERES = 20;
const SPHERE_RADIUS = 0.2;
const STEPS_PER_FRAME = 5;
const sphereGeometry = new THREE.SphereGeometry( SPHERE_RADIUS, 32, 32 );
const sphereMaterial = new THREE.MeshStandardMaterial( { color: 0x888855, roughness: 0.8, metalness: 0.5 } );
......@@ -360,13 +362,20 @@
function animate() {
const deltaTime = Math.min( 0.1, clock.getDelta() );
const deltaTime = Math.min( 0.05, clock.getDelta() ) / STEPS_PER_FRAME;
// we look for collisions in substeps to mitigate the risk of
// an object traversing another too quickly for detection.
for ( let i = 0 ; i < STEPS_PER_FRAME ; i ++ ) {
controls( deltaTime );
controls( deltaTime );
updatePlayer( deltaTime );
updatePlayer( deltaTime );
updateSpheres( deltaTime );
updateSpheres( deltaTime );
}
renderer.render( scene, camera );
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册