Look at a 2D point in screen space
the object to look at the point
the target point in 2D screen space XY e.g. from a mouse event
the camera to use for the lookAt
the factor to multiply the distance from the camera to the object. Default is 1
the target point in world space
export class MyLookAtComponent extends Behaviour { update() { lookAtScreenPoint(this.gameObject, this.context.input.mousePosition, this.context.mainCamera); } } Copy
export class MyLookAtComponent extends Behaviour { update() { lookAtScreenPoint(this.gameObject, this.context.input.mousePosition, this.context.mainCamera); } }
window.addEventListener("mousemove", (e) => { lookAtScreenPoint(object, new Vector2(e.clientX, e.clientY), camera); }); Copy
window.addEventListener("mousemove", (e) => { lookAtScreenPoint(object, new Vector2(e.clientX, e.clientY), camera); });
Look at a 2D point in screen space