Unable to convert screen coordinate to world coordinates

@slackmoehrle I’m unable to convert screen coordinate to world coordinates.
Below is the code I have used.

console.log("screen ",touch.getLocation());
var touchPoint: Vec2 = touch.getLocation();
var worldTouchPoint: Vec3 = new Vec3();
this.camera.camera.screenToWorld(worldTouchPoint, new Vec3(touchPoint.x, touchPoint.y, 0.5));
console.log("world ", worldTouchPoint);

Below is the result I’m getting which is not the proper world coordinate. But the values I get from raycast hitpoint is proper.
What I want is pick up a object and move it around using TOUCH_MOVE.
And also is the touch.getLocation() returns double of the screen dimension, like if the screen resolution is 360x640, and top right part of the screen is (360, 640) but the getLocation() returns (720, 1280). the values are multiplied by 2. Can I know why it is like that?
Thank you

1 Like

I can ask engineering to have a look. What version of Creator are you using?

Thank you for providing a code sample.

1 Like

cocos creator 3.3.2

1 Like

@slackmoehrle the problem was the depth value passed which is 0.5 in the below code.

I wrote a function to get that value, it works fine now.

getDepthValue(height: number = 0){
        var z = this.camera.node.getPosition().y - height;
        var normZ = (z - this.camera.near) / (this.camera.far - this.camera.near);
        console.log("normalised z ", normZ);
        return normZ;

Now I’m able to move the object with mouse drag, but physics won’t work in this case. Is there a Mouse Joint class for 3D? or how can I use the physics when changing its position on mouse move?
Thank you


Is there a solution to this?

What is the engine version used?

latest version 3.3.2

Can you provide a demo?

I will try to create a demo and share it here.

I am currently using this as z value to convert screen to world coordinate which is working fine. Currently when I pick up the object in top of the screen, objects seem to be moved much higher than the objects picked up at the bottom of the screen. Is there a way to move the objects to the same height when picked up across the screen?
I am using ortho camera. and is rotated around X-axis by -75
Screenshot (21)
Screenshot (22)

Thank you

Do you mean the shadows are at different distances from the sphere?
This question requires a specific project to determine the problem.