Using screenToWorld

I have a problem with screenToWorld function
I want to get position of my click on screen and then move my 3d node to this position
But I’m getting the same values with event.getLocation and screenToWorld (using canvas camera)
What am I doing wrong?

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

What exactly my question is - how to translate ui node coordinate into 3d world objects coordinate system?

you can refer to : (7.9 KB)

Hi linrm!
Thank you for example
Now everything is good and working as expected
But I’m curious about why do I need a parent node to cube with UITransform component. It doesn’t look obvious to me

Because the cube has a 100x scaling.

Can I achieve screen to world transformation without having UITransform component on my 3d object?

you can use setWorldPosition.

1 Like