Cocos Creator 2.4.3 camera.getWorldToScreenPoint is offset on mobile

I’m making a project where I’m trying to place a sprite in canvas over a 3D object in 3D space. The code attached to the sprite looks something like this:

    update (dt) {
        const position: cc.Vec3 = this.camera.getWorldToScreenPoint(this.target.position);
        this.node.setPosition(this._canvas.convertToNodeSpaceAR(new cc.Vec2(position.x, position.y)));
    }

While it works perfectly fine in browser on desktop, when I run it on mobile the sprite is significantly offset (the sprite in question is the white square crosshair and the target is the red cube):

Is this a bug or am I doing something wrong?

CameraToScreenTest.zip (241.5 KB)

1 Like

@slackmoehrle @huanxinyin @jare could you check this issue

I am happy to ask engineering to look at this topic. Give them a bit of time.

1 Like

@QuickArgentum Use new API to fix it, try this code.
TrackTarget.ts.zip (966 Bytes)

2 Likes

This topic was automatically closed 24 hours after the last reply. New replies are no longer allowed.