private void intentYDir(Vector3 dir) { if (dir.y != 0) { if(yMoveState == Y_MOVE_STATE.NONE) { if(dir.y > 0) { yMoveState = Y_MOVE_STATE.JUMP; changeYSpeed(JUMP_SPEED); } }else if(yMoveState == Y_MOVE_STATE.JUMP) { } } }
void Start() { xzMoveState = XZ_MOVE_STATE.NONE; yMoveState = Y_MOVE_STATE.NONE; }
//-------------------------------------simple Physics--------------------------------- private void handlePhysics() { //check up down if (yMoveState == Y_MOVE_STATE.JUMP) { gravityTimeClapsed += Time.deltaTime; yspeed = yJumpSpeed + gravityTimeClapsed * GRAVITY;//瞬时y速度 yspeed = Mathf.Clamp(yspeed,-MAX_SPEED,MAX_SPEED); //判断脚底 if(yspeed <= 0) { if(world.isLand(new Vector3(trans.localPosition.x,trans.localPosition.y + yspeed*Time.deltaTime,trans.localPosition.z))) { yspeed = 0; yMoveState = Y_MOVE_STATE.NONE; } }else if(world.isLand(new Vector3(trans.localPosition.x,trans.localPosition.y + yspeed*Time.deltaTime + 1.5f * BODY_HALF_SIZE_Y,trans.localPosition.z))) { //判断头顶撞到阻挡 yspeed = 0; } } else if (yMoveState == Y_MOVE_STATE.NONE) { } //check f b l r if (xzMoveState == XZ_MOVE_STATE.WALK) { if(yMoveState == Y_MOVE_STATE.NONE) { if (!world.isLand(new Vector3(trans.localPosition.x,trans.localPosition.y - 0.1f * CubeCell.BASIC_SIZE,trans.localPosition.z))) { yMoveState = Y_MOVE_STATE.JUMP; changeYSpeed(0); } } //检测行走方向碰撞 if(xspeed != 0) { int dir = 1; if(xspeed < 0) { dir = -1; } //判断半身(1/4)和头顶(3/4) if (world.isLand(new Vector3(trans.localPosition.x + BODY_HALF_SIZE_X*dir + xspeed*Time.deltaTime,trans.localPosition.y + BODY_HALF_SIZE_Y * 0.5f,trans.localPosition.z))) { xspeed = 0; }else if(world.isLand(new Vector3(trans.localPosition.x + BODY_HALF_SIZE_X*dir + xspeed*Time.deltaTime,trans.localPosition.y + BODY_HALF_SIZE_Y * 1.5f,trans.localPosition.z))) { xspeed = 0; } } if(zspeed != 0) { int dir = 1; if(zspeed < 0) { dir = -1; } if (world.isLand(new Vector3(trans.localPosition.x,trans.localPosition.y + BODY_HALF_SIZE_Y * 0.5f,trans.localPosition.z + BODY_HALF_SIZE_Z*dir + zspeed*Time.deltaTime))) { zspeed = 0; }else if(world.isLand(new Vector3(trans.localPosition.x,trans.localPosition.y + BODY_HALF_SIZE_Y * 1.5f,trans.localPosition.z + BODY_HALF_SIZE_Z*dir + zspeed*Time.deltaTime))) { zspeed = 0; } } } //real speed trans.localPosition = new Vector3 (trans.localPosition.x + xspeed*Time.deltaTime, trans.localPosition.y + yspeed*Time.deltaTime, trans.localPosition.z + zspeed*Time.deltaTime); }