Pool/Billard game made with BabylonJs

Alright guys! This is my solution. I hope that it will help someone!

/**
   * Set White ball direction based on pointer inputs
   * @param hitInfo Vector3
   */
  public setDirection (hitInfo: Vector3): void {
    const direction = hitInfo.subtract(this.getPosition())
    const angle = (Math.atan2(direction.z, direction.x) - Math.PI / 2) % (2 * Math.PI)
    const vectorUp = new Vector3(0, 1, 0)
    const targetRotation = Quaternion.RotationAxis(vectorUp, -angle)
    this.setRotationQuaternion(targetRotation) // custom for : this.mesh.rotationQuaternion = quaternion

    // this.setRotation(new Vector3(0, -angle, 0))
    // this.rotateMesh(vectorUp, -angle, Space.LOCAL)
  }
1 Like