我试图创建一个浏览器VR游戏,设置了世界,VR控制器,创建了触发事件,但是每次我扣动扳机时,之前发射的子弹就会消失。当我发射新子弹时,如何使子弹“停留”在场景中并保持移动?
我正在跟踪此示例https://threejs.org/examples/#webvr_ballshooter,但这并不是我真正需要的
var geometry_bullet = new THREE.IcosahedronBufferGeometry( radius, 2 );
var bullet1 = new THREE.Mesh( geometry_bullet, new THREE.MeshLambertMaterial( { color: 0x2661b9 } ) );
bullet1.userData.velocity = new THREE.Vector3();
bullet1.userData.velocity.x = 10;
bullet1.userData.velocity.y = 10;
bullet1.userData.velocity.z = 10;
var bullet2 = new THREE.Mesh( geometry_bullet, new THREE.MeshLambertMaterial( { color: 0xee2f2f } ) );
bullet2.userData.velocity = new THREE.Vector3();
bullet2.userData.velocity.x = 1;
bullet2.userData.velocity.y = 1;
bullet2.userData.velocity.z = 1;
...
function handleController( controller ) {
if ( controller1.userData.isSelecting ) {
bullet1.position.set(controller1.position.x , controller1.position.y + 0.018 , controller1.position.z );
bullet1.userData.velocity.x = 0;
bullet1.userData.velocity.y = 10;
bullet1.userData.velocity.z = 10;
bullet1.userData.velocity.applyQuaternion( controller1.quaternion );
}
if ( controller2.userData.isSelecting ) {
bullet2.position.set(controller2.position.x , controller2.position.y + 0.018 , controller2.position.z );
bullet2.userData.velocity.x = 0;
bullet2.userData.velocity.y = 10;
bullet2.userData.velocity.z = 10;
bullet2.userData.velocity.applyQuaternion( controller2.quaternion );
}
} ...
function render() { ...
handleController( controller1 );
handleController( controller2 ); ...
bullet1.position.x -= bullet1.userData.velocity.x * delta;
bullet1.position.y -= bullet1.userData.velocity.y * delta;
bullet1.position.z -= bullet1.userData.velocity.z * delta;
scene.add(bullet1);
bullet2.position.x -= bullet2.userData.velocity.x * delta;
bullet2.position.y -= bullet2.userData.velocity.y * delta;
bullet2.position.z -= bullet2.userData.velocity.z * delta;
scene.add(bullet2);
...
renderer.render( scene, camera );
}