Advertisement
sebbu

character movement

May 30th, 2015
466
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. function input(){
  2.     //var RayLeft = new THREE.Raycaster(THREE.Vector3(player.position.x,player.position.y-0.15, player.position.z ),THREE.Vector3(0,0,0.1));
  3.     //var RayRight = new THREE.Raycaster(THREE.Vector3(player.position.x,player.position.y-0.15, player.position.z ),THREE.Vector3(0,0,-0.1));
  4.    
  5.    
  6.    
  7.     var leftpnt = new THREE.Vector3( -0.1,0,0 );
  8.     var rightpnt= new THREE.Vector3( 0.1,0,0 );
  9.     var uppnt   = new THREE.Vector3( 0,0,-0.1 );
  10.     var downpnt = new THREE.Vector3( 0,0,0.1 );
  11.  
  12.  
  13.     /// experimental raycast test
  14.     var startPnt = new THREE.Vector3( player.position.x,player.position.y-0.2, player.position.z );
  15.     var endPnt = new THREE.Vector3( 0,-0.1,0 );
  16.     //cube.position.set(player.position.x,player.position.y, player.position.z);
  17.     var testRay = new THREE.Raycaster(startPnt,endPnt);
  18.     testRay.set(startPnt,endPnt);
  19.     var testIntersects = testRay.intersectObjects(scene.children);
  20.     if ( testIntersects.length > 0) {
  21.         //alert("this got trigerd");
  22.         setMaterial(cube,Matswap);
  23.         //testIntersects[ 1 ].object.material.color.set( 0xff0000 );
  24.         player.position.y += 0.01;
  25.     }
  26.     else{
  27.         setMaterial(cube,material);
  28.         player.position.y += -0.01;
  29.     }
  30.  
  31.     ///
  32.     leftRay = new THREE.Raycaster(startPnt,leftpnt);
  33.     leftRay.set(startPnt,leftpnt);
  34.     leftIntersect   = leftRay.intersectObjects(scene.children);
  35.     if (keyboard.pressed("left") && leftIntersect.length < 1)
  36. {
  37. player.position.x += -0.1;
  38. startPnt = new THREE.Vector3( player.position.x,player.position.y-0.2, player.position.z );
  39. }
  40.     rightRay= new THREE.Raycaster(startPnt,rightpnt);
  41.     rightRay.set(startPnt,rightpnt);
  42.     rightIntersect  = rightRay.intersectObjects(scene.children);
  43.     if (keyboard.pressed("right")&& rightIntersect.length < 1)
  44. {
  45. player.position.x +=0.1;
  46. startPnt = new THREE.Vector3( player.position.x,player.position.y-0.2, player.position.z );
  47. }
  48.     upRay   = new THREE.Raycaster(startPnt,uppnt);
  49.     upRay.set(startPnt,uppnt);
  50.     upIntersect     = upRay.intersectObjects(scene.children);
  51.     if (keyboard.pressed("up")   && upIntersect.length < 1)
  52. {
  53. player.position.z += -0.1;
  54. startPnt = new THREE.Vector3( player.position.x,player.position.y-0.2, player.position.z );
  55. }
  56.     downRay = new THREE.Raycaster(startPnt,downpnt);
  57.     downRay.set(startPnt,downpnt);
  58.     downIntersect   = downRay.intersectObjects(scene.children);
  59.     if (keyboard.pressed("down") && downIntersect.length < 1)
  60. {
  61. player.position.z += 0.1;
  62. //no need for it, no further tests
  63. }
  64.     ///
  65.  
  66.     //if (upIntersect.length > 0) {
  67.     //  player.position.z = upIntersect[0].point.z + 0.01;
  68.     //};
  69. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement