I’m having problems implementing the steering of the player in my current project.
Left mouse button should trigger firing, right mouse button should trigger acceleration.
It already works to a certain degree, but I’m struggling to implement the behavior that when the right mouse button (acceleration) is held down it still is possible to trigger fire with left mouse button without stopping acceleration. Here is a playground which only implements non-simultaneously pressed buttons https://playground.babylonjs.com/#T4MJ6I#3. The left box indicates firing with CCW rotation, the right box indicates acceleration with CW rotation.
According to MouseEvent.buttons - Web APIs | MDN the event.buttons property indicates simultaneously pressed buttons which probably can be used to aceive what I’m looking for. But all attempts messing around with this property failed. Maybe someone already has done something similar in the past and could modify the playground.
Does this do what you’re looking for? The only changes I made were to remove the state reset on controlEnabled and switch the setting of your acceleration flags to depend only on the buttons variable, which uses bit flags to indicate which mouse buttons are currently pressed. I think it works pretty well, though if there were special cases you were guarding against with some of those conditions I removed, you should double-check that those cases aren’t broken now.
Hi community,
it seems something has changed regarding the detection of simultaneously pressed mousebuttons since 4.2.0. With latest 5.0 it doesn’t work anymore. Maybe someone can have a look, see this PG https://playground.babylonjs.com/#T4MJ6I#5
So here’s an update with this. Based on what I’m seeing, it looks like the current system is registering the simultaneous input but not properly triggering the proper observer. I have noticed that when you hold both left and right click down and then move the mouse, both squares will rotate. I’m going to continue to figure out why each isn’t firing properly and will update this thread when I having things figure out and have a fix in the works.
Recently, I pushed some changes to set pointer capture for input but I’m not sure why it’s throwing an InvalidStateError. I’ll try to look at it this week and see what’s happening.
So here’s what I’ve found. In the current code, we set pointer capture when we get a pointer down event so that we can track input, if it leaves the window before the button that initiated the pointer down event is release. Pointer capture can’t be set when a pointer lock is set.
I am currently testing a fix where we check for pointer lock before using setPointerCapture and should have a PR up sometime today.