ScreenToWorld Zdepth issue

Hello All,
I hope you all are doing fine, please help me I am stuck at one point,
the Z depth in the ScreenToWorld is causing issues. Please check my code.

Issue: The main issue is that the touch event is only detected at a depth of 18, and as you can see when I touch far away on the platform the ball wont move their as the depth is 18 while the camera’s far is 70 and min is 0 as set in the editor.
Please help me in this regard.

// Moving ball using Touch Move
PlayerController.prototype.onTouchMove = function(event){

if(GetTouchPos === true){   // For Panning
    if(typeof !== 'undefined'){
        // Getting position for the ball
        var from = this.entity.getPosition();
        // Getting touch position ~ zdepth = 18 causing issues, different values causing different issues.
        // Z depth cauing issue
        this.pos =[0].x, event.touches[0].y, 18); // ISSUE here

        // Getting the direction 
        // Getting the distance 
        this.Distance = this.Direction.length();
        // Normalize Vector 
        // Making y = 0 so ball does not fly upwards

        if(canPlay === true){  // If we are playing the game
            // Using the direction vector to translate the ball towards the touched position.



The project is here:

The Build is here:

What you will need to do is to project a ray from the camera to (and through) the world point from screenToWorld to check for intersection against a plane that is level with the ball.

Here’s an example:

1 Like

Yes I got the code working perfectly!
Thank you yaustar! Really appreciate the help.