this.offsetX = view.getVisibleSize().width / 2;

this.offsetY = view.getVisibleSize().height / 2;

private onMouseHover(touch: EventTouch): void {

const touchLocation = touch.getLocation();

let v3Touch: Vec3 = new Vec3(touchLocation.x, touchLocation.y, 0);

let v2Touch = v3Touch.clone().subtract(new Vec3(this.offsetX, this.offsetY));

if (!this.isAttackTarget) {

const diff = v2Touch.clone().subtract(this.gun.getPosition());

const angle = (Math.atan2(diff.x, diff.y) * 180) / Math.PI;

this.gun.angle = -angle;

}

if (this.isTargetFish) {

log(v2Touch, “v2Touch”);

this.nodeTargetMouse.setPosition(v2Touch);

}

}

I am having a problem where the mouse position is being detected wrongly. What is wrong with the code above? Please, help me!

I can see one problem at a glance, clone and subtract function please use in a proper way, here is example:

let v3Clone = Vec3.clone(v3Touch);

let v3out = new Vec3();

let v2Touch = Vec3.subtract(v3out, v3Clone, new Vec3(this.offsetX, this.offsetY,0));

I see that v2Touch still doesn’t accurately position the mouse when I move it

you can use getUILocation or getLocationInView for a try , Or could you provide the demo for me to check?

Thank you, I have successfully fixed the error. I made the mistake of taking canvas position and worldspace to calculate diff