Set Power To Ball

Hello guys,

I need some help, cause I cant find some solution, of I dont know how do that. I have ball game, simply throwing ball to hoop. For now, I just throwing with mouse move, or touch move, when if the touch or mouse is in some height, the ball automatically will throw with some impulse. But i need set Power of ball. It means, that if my touch will be lower, the impulse will be lower too. If the touch will be higher and higher, the power of ball will increase. I am so tired cause i m trying but nothing worked.
I put it some code:

This function is called on Mouse move or Touch move and set screen to World function on each possitions of the ball:

BallMovement.prototype.updateFromScreen = function (screenPos) {

  var canTeleport = true;
     var context = this;
    
    var cameraEntity = this.app.root.findByName('Camera');
    
        
        this.pos = new pc.Vec3();
        this.pos2 = new pc.Vec3();
        this.pos3 = new pc.Vec3();

         if(CameraCollision.changePositions ==1 && this.isBallClicked && canTeleport) {
             
           var depth = 7.1;
       
         cameraEntity.camera.screenToWorld(screenPos.x, screenPos.y, depth, this.pos);
        
        this.ball.setLocalPosition(this.pos.x, this.pos.y, this.ball.getLocalPosition().z);

         }

        
        else if(CameraCollision.changePositions == 2 && this.isBallClicked && canTeleport) {
            
            var depth2 = 8;
           
            if(Init.portrait) {
           cameraEntity.camera.screenToWorld(screenPos.x /1.6, screenPos.y, 
             depth2, this.pos2);
            }
            else if (Init.landscape) {
                
               cameraEntity.camera.screenToWorld(screenPos.x *0.96 , screenPos.y, depth2, this.pos2);
            }
            
              this.ball.setLocalPosition(this.pos2.x   , this.pos2.y  , this.ball.getLocalPosition().z);
            

        }
         
  
         else if(CameraCollision.changePositions ==3 && this.isBallClicked && canTeleport) {
              var depth3 =7.1;
             if(Init.portrait) {
           cameraEntity.camera.screenToWorld(screenPos.x *1.78, screenPos.y, depth3, this.pos3);
             }else if (Init.landscape) {
                 
             cameraEntity.camera.screenToWorld(screenPos.x * 1.13 , screenPos.y, depth3, this.pos3);
             }
                 
                 
             this.ball.setLocalPosition(this.pos3.x , this.pos3.y  , this.ball.getLocalPosition().z);

        }
        

I had in this function also the impulses, so when screenPos.y was higher then window.innerHeight /1.3 and lower than 1.5 … the Impuls will be applied

But i need to do that on Mouse up or Touch end, so if you leave Mouse or Touch in area between 1.3 and 1.5 of screenPos y, the impulz will be aplied with power.
If you leave Mouse or Touch in area between 1.5 and 1.7, the impulz will be higher and so on.

Here is the code on Touch end:

BallMovement.prototype.onTouchEnd = function(screenPos){
  
   
    this.ball.rigidbody.type = pc.BODYTYPE_DYNAMIC;
    this.isBallClicked = false;
    this.wasTouchUp = true;
 
    
    console.log('na end je' + this.wasTouchUp);
    this.updateFromScreen();
  
    
     if(Init.portrait) {
          
          
    
        if( screenPos.y <= window.innerHeight/1.4&& screenPos.y > window.innerHeight /1.5 && this.canShot && this.isBallClicked  ) {
               
            this.shotBall();
            this.cameraFollow();
            
          if(CameraCollision.changePositions == 1) {
              
               this.entity.rigidbody.applyImpulse(this.pos.x*2.2, 6.2, - 3.4);
              
              
          }
            else if(CameraCollision.changePositions == 2) {
                
                 this.entity.rigidbody.applyImpulse(this.pos2.x*2.2, 6.2, - 3.4);
            
        }
            else  if(CameraCollision.changePositions == 3) {
                this.entity.rigidbody.applyImpulse(this.pos3.x*2.2, 6.2, - 3.4);
                
            }
            
        }
          
         else if(screenPos.y <= window.innerHeight/1.5&& screenPos.y > window.innerHeight/1.6 && this.canShot && this.isBallClicked ) {
            
      
            this.shotBall();
            this.cameraFollow();
            
          if(CameraCollision.changePositions == 1) {
              
               this.entity.rigidbody.applyImpulse(this.pos.x*2.2, 6.2, - 3.4);
              
              
          }
            else if(CameraCollision.changePositions == 2) {
                
                 this.entity.rigidbody.applyImpulse(this.pos2.x*2.2, 6.2, - 3.4);
            
        }
            else  if(CameraCollision.changePositions == 3) {
                this.entity.rigidbody.applyImpulse(this.pos3.x*2.2, 6.2, - 3.4);
                
            }
            
        }
          
           else if( screenPos.y <= window.innerHeight/1.6&& screenPos.y >window.innerHeight/ 1.7 && this.canShot && this.isBallClicked) {
            
     
            this.shotBall();
            this.cameraFollow();
            
          if(CameraCollision.changePositions == 1) {
              
               this.entity.rigidbody.applyImpulse(this.pos.x*2.2, 6.2, - 3.4);
              
              
          }
            else if(CameraCollision.changePositions == 2) {
                
                 this.entity.rigidbody.applyImpulse(this.pos2.x*2.2, 6.2, - 3.4);
            
        }
            else  if(CameraCollision.changePositions == 3) {
                this.entity.rigidbody.applyImpulse(this.pos3.x*2.2, 6.2, - 3.4);
                
            }
            
        }
      }
             
};

Thise code will never execute cause it dont know what screenPos is now. I know that i need put that informations from Touch move or maybe not, maybe i should do something else.

If you have some time for me, please help cause I dont know how do that.
Thank you so much.