this.offsetX = view.getVisibleSize().width / 2;
this.offsetY = view.getVisibleSize().peak / 2;
personal onMouseHover(contact: EventTouch): void {
const touchLocation = contact.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’m having an issue the place the mouse place is being detected wrongly. What’s improper with the code above? Please, assist me!
I can see one drawback at a look, clone and subtract operate please use in a correct method, right here is instance:
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 nonetheless doesn’t precisely place the mouse once I transfer it
you should use getUILocation or getLocationInView for a strive , Or may you present the demo for me to examine?
Are you able to have a look and assist me see what’s improper? Thanks very a lot