Пример #1
0
  public void update(float delta, Camera c) {

    heal(healthregen * delta);
    regenerateMana(manaregen * delta);

    if (!isJumping && input.isJumpPressed()) {
      characterController.jump();
      animations.setAnimation("Jumping");
      isJumping = true;
    } else {
      isJumping = false;
    }
    if (!isPerformingRightAction && input.isRightHandPressed()) {
      isPerformingRightAction = true;
      rightweapon.onAttackStart();
      rightActionTimer += delta;
    } else if (isPerformingRightAction) {
      rightActionTimer += delta;
      if (rightActionTimer > rightweapon.attacktime) {
        rightActionTimer = 0;
        isPerformingRightAction = false;
        rightweapon.onAttackEnd();
      }
    }
    if (!isPerformingLeftAction && input.isLeftHandPressed()) {
      leftweapon.onAttackStart();
      isPerformingLeftAction = true;
      leftActionTimer += delta;
    } else if (isPerformingLeftAction) {
      leftActionTimer += delta;
      if (leftActionTimer > leftweapon.attacktime) {
        leftActionTimer = 0;
        isPerformingLeftAction = false;
        rightweapon.onAttackEnd();
      }
    }
    Vector3 movement = new Vector3();
    Vector3 back = new Vector3(c.direction.x, c.direction.y, 0).nor();
    back.nor();
    movement.add(back.cpy().scl(input.getForward()));
    movement.add(back.cpy().crs(0, 0, 1).scl(input.getRight()));
    movement.nor();
    movement.scl(input.isSprintPressed() ? 5 : 1);
    characterController.setWalkDirection(movement.cpy().scl(delta * runspeed));

    if (movement.len() != 0) {
      face = movement.cpy().scl(-1);
      if (characterController.canJump()) {
        animations.setAnimation("Walking", -1, 0.4f * movement.len() * runspeed, null);
      }
    } else {
      if (characterController.canJump()) {
        animations.setAnimation(null);
      }
    }
    mi.transform.set(ghostObject.getWorldTransform().translate(0, 0, -0.25f));
    mi.transform.rotate(0, 0, -1, (float) Math.toDegrees(Math.atan2(face.x, face.y)));
    updateWeaponInstances();
    animations.update(delta);
  }
Пример #2
0
 private static Vector3 calcNor(Vector3 v1, Vector3 v2, Vector3 v3) {
   _A = v2.cpy();
   _A.sub(v1);
   _B = v3.cpy();
   _B.sub(v2);
   _n = _A.crs(_B).nor();
   return _n;
 }
Пример #3
0
  public Vector3[] getNinePoints() {
    Vector3[] nine = new Vector3[8];

    CubeVertex[] vertexes = getVerts();
    for (int i = 0; i < vertexes.length; i++) {
      float[] pos = vertexes[i].getPosition();
      nine[i] = new Vector3(pos[0], pos[1], pos[2]);
    }

    for (int i = 0; i < vertexes.length; i++) {
      Vector3 prev = nine[i];
      Vector3 next = nine[(i + 1) % vertexes.length];
      nine[vertexes.length + i] = next.cpy().sub(prev).mul(0.5f).add(prev);
    }

    //  System.out.println("INIT " + Arrays.toString(nine));
    /*  if (NINE_OFFSET != 0) {
        Vector3 origin = nine[nine.length - 1].cpy();
        for (int i = 0; i < nine.length; i++) {
            nine[i].sub(origin);
            nine[i].mul(1 - NINE_OFFSET);
            nine[i].add(origin);
        }
    }*/

    //  System.out.println("     " + Arrays.toString(nine));
    return nine;
  }