playcanvas / playcanvas/engine
Element input with mouse pointer locked
Nobody has claimed this yet.
- 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
First steps
- Read the whole issue, then the project's contributing guide.
- Comment on the issue to say you are picking it up — it saves two people doing the same work.
- Fork the repository and make your change on a branch.
- 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