function world_moveObject(object, xChange, yChange, zChange) {
  let newX = object.x;
  let newY = object.y;
  let newZ = object.z;

  // y movement
  let yChangeAbs = Math.abs(yChange);
  let ySign = Math.sign(yChange);
  let yOffset = yChange > 0 ? PLAYER_HEIGHT+1 : 0;

  // down movement
  
  for (let y=0; y<yChangeAbs+RAY_TRACE_INCREMENT; y+=RAY_TRACE_INCREMENT) {
    if (y > yChangeAbs) {
      y = yChangeAbs;
    }
    let block = world_getBlock(object.x, object.y + y*ySign + yOffset, object.z);
    if (block) {
      object.upVelocity = 0;

      // if landed on block
      if (yChange < 0) {
        object.isAirborne = false;
        player_jumpNum = 0;
      }
      
      break;
    }
    else {
      newY = object.y + y*ySign;
    }
  }
  

  // x movement
  let xChangeAbs = Math.abs(xChange);
  let xSign = Math.sign(xChange);
  for (let x=0; x<xChangeAbs+RAY_TRACE_INCREMENT; x+=RAY_TRACE_INCREMENT) {
    if (x > xChangeAbs) {
      x = xChangeAbs;
    }
    let block = world_getBlock(object.x + x*xSign + 0.5*xSign, newY, object.z);
    if (block) {
      // handle auto up step
      let blockAboveStep = world_getBlock(object.x + x*xSign + 0.5*xSign, newY+1, object.z);
      if (!blockAboveStep) {
        newY += 1;
      }

      break;
    }
    else {
      newX = object.x + x*xSign;
    }


  }

  // z movement
  let zChangeAbs = Math.abs(zChange);
  let zSign = Math.sign(zChange);
  for (let z=0; z<zChangeAbs+RAY_TRACE_INCREMENT; z+=RAY_TRACE_INCREMENT) {
    if (z > zChangeAbs) {
      z = zChangeAbs;
    }
    let block = world_getBlock(newX, newY, object.z + z*zSign + 0.5*zSign);
    if (block) {
      // handle auto up step
      let blockAboveStep = world_getBlock(newX, newY+1, object.z + z*zSign + 0.5*zSign);
      if (!blockAboveStep) {
        newY += 1;
      }

      break;
    }
    else {
      newZ = object.z + z*zSign;
    }
  }

  object.x = newX;
  object.y = newY;
  object.z = newZ;


  
}
// use ray tracing to find collisions
use ray tracing to find collisions
use ray tracing to find collisions
function world_moveObject(object, xChange, yChange, zChange) {
  let newX = object.x;
  let newY = object.y;
  let newZ = object.z;
  let yChangeAbs = Math.abs(yChange);
  let ySign = Math.sign(yChange);
  let yOffset = yChange > 0 ? PLAYER_HEIGHT+1 : 0;
  for (let y=0; y<yChangeAbs+RAY_TRACE_INCREMENT; y+=RAY_TRACE_INCREMENT) {
    if (y > yChangeAbs) {
      y = yChangeAbs;
    }
    let block = world_getBlock(object.x, object.y + y*ySign + yOffset, object.z);
    if (block) {
      object.upVelocity = 0;
      if (yChange < 0) {
        object.isAirborne = false;
        player_jumpNum = 0;
      }
      break;
    }
    else {
      newY = object.y + y*ySign;
    }
  }
  let xChangeAbs = Math.abs(xChange);
  let xSign = Math.sign(xChange);
  for (let x=0; x<xChangeAbs+RAY_TRACE_INCREMENT; x+=RAY_TRACE_INCREMENT) {
    if (x > xChangeAbs) {
      x = xChangeAbs;
    }
    let block = world_getBlock(object.x + x*xSign + 0.5*xSign, newY, object.z);
    if (block) {
      let blockAboveStep = world_getBlock(object.x + x*xSign + 0.5*xSign, newY+1, object.z);
      if (!blockAboveStep) {
        newY += 1;
      }
      break;
    }
    else {
      newX = object.x + x*xSign;
    }
  }
  let zChangeAbs = Math.abs(zChange);
  let zSign = Math.sign(zChange);
  for (let z=0; z<zChangeAbs+RAY_TRACE_INCREMENT; z+=RAY_TRACE_INCREMENT) {
    if (z > zChangeAbs) {
      z = zChangeAbs;
    }
    let block = world_getBlock(newX, newY, object.z + z*zSign + 0.5*zSign);
    if (block) {
      let blockAboveStep = world_getBlock(newX, newY+1, object.z + z*zSign + 0.5*zSign);
      if (!blockAboveStep) {
        newY += 1;
      }
      break;
    }
    else {
      newZ = object.z + z*zSign;
    }
  }
  object.x = newX;
  object.y = newY;
  object.z = newZ;
}
function world_moveObject ( object , xChange , yChange , zChange ) { let newX = object . x ; let newY = object . y ; let newZ = object . z ; let yChangeAbs = Math . abs ( yChange ) ; let ySign = Math . sign ( yChange ) ; let yOffset = yChange > 0 ? PLAYER_HEIGHT + 1 : 0 ; for ( let y = 0 ; y < yChangeAbs + RAY_TRACE_INCREMENT ; y += RAY_TRACE_INCREMENT ) { if ( y > yChangeAbs ) { y = yChangeAbs ; } let block = world_getBlock ( object . x , object . y + y * ySign + yOffset , object . z ) ; if ( block ) { object . upVelocity = 0 ; if ( yChange < 0 ) { object . isAirborne = false ; player_jumpNum = 0 ; } break ; } else { newY = object . y + y * ySign ; } } let xChangeAbs = Math . abs ( xChange ) ; let xSign = Math . sign ( xChange ) ; for ( let x = 0 ; x < xChangeAbs + RAY_TRACE_INCREMENT ; x += RAY_TRACE_INCREMENT ) { if ( x > xChangeAbs ) { x = xChangeAbs ; } let block = world_getBlock ( object . x + x * xSign + 0.5 * xSign , newY , object . z ) ; if ( block ) { let blockAboveStep = world_getBlock ( object . x + x * xSign + 0.5 * xSign , newY + 1 , object . z ) ; if ( ! blockAboveStep ) { newY += 1 ; } break ; } else { newX = object . x + x * xSign ; } } let zChangeAbs = Math . abs ( zChange ) ; let zSign = Math . sign ( zChange ) ; for ( let z = 0 ; z < zChangeAbs + RAY_TRACE_INCREMENT ; z += RAY_TRACE_INCREMENT ) { if ( z > zChangeAbs ) { z = zChangeAbs ; } let block = world_getBlock ( newX , newY , object . z + z * zSign + 0.5 * zSign ) ; if ( block ) { let blockAboveStep = world_getBlock ( newX , newY + 1 , object . z + z * zSign + 0.5 * zSign ) ; if ( ! blockAboveStep ) { newY += 1 ; } break ; } else { newZ = object . z + z * zSign ; } } object . x = newX ; object . y = newY ; object . z = newZ ; }
use ray tracing to find collisions
use ray tracing to find collisions
// y movement // down movement // if landed on block // x movement // handle auto up step // z movement // handle auto up step