playcanvas / playcanvas/engine

Element input with mouse pointer locked

Open
#3,718 1 comment 0 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

area: input area: ui enhancement
Dominant language
JavaScript
Stars
16.8k
Forks
2k
Avg merge
4h 32m
Merged PRs (30d)
222

Description

Right now when the mouse pointer is locked you aren't really able to receive input in world placed UI elements (e.g. 3D screens with buttons).

It would be cool to support this one way or another, interface elements placed in world screens are quite a thing in many first person games.

One easy way for developers to approach this, is by using an internal/private method from the pc.ElementInput class. Example code:

this.app.mouse.on("mouseup", function (e) {

    // --- if pointer is locked we handle our own element input
    if(pc.Mouse.isPointerLocked() === true & e.button === pc.MOUSEBUTTON_LEFT){

        const centerX = this.app.graphicsDevice.canvas.width / 2;
        const centerY = this.app.graphicsDevice.canvas.height / 2;

        const target = this.app.elementInput._getTargetElement(this.entity.camera, centerX, centerY);

        if(target) target.fire('click');
    }
}, this);  

Basically this is a feature request to expose the _getTargetElement method as public API, unless there is formal support for this feature to be discussed.

Contributor guide

Open the contributing guide

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

Research direction

Start with the pc.ElementInput class and its _getTargetElement method, then inspect how pointer-lock input and world-placed UI elements are currently handled. Decide whether exposing that method or adding formal pointer-lock support fits the existing API; done means developers can receive input from world UI while the pointer is locked through supported engine behavior.

Written by the indexing model from the issue text.

Assessment

Tech stack
javascript
Domain
game-dev
Issue type
Feature
Difficulty
4/5
Estimated time
3-5 days
Activity status
Stale
Clarity
Mostly clear
Newbie friendliness
35/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.