fixed pointerlock securityerror
This commit is contained in:
parent
b017beca2d
commit
6c3e1ae64e
|
|
@ -69,7 +69,7 @@ export const PlayerObjectView = observer(function ({ object, objectType }: Playe
|
||||||
|
|
||||||
useEffect(() => {
|
useEffect(() => {
|
||||||
const canvas = gl.domElement;
|
const canvas = gl.domElement;
|
||||||
const onClick = () => canvas.requestPointerLock();
|
const onClick = () => { if (document.pointerLockElement !== canvas) canvas.requestPointerLock()?.catch(() => {}); };
|
||||||
const onMouseMove = (e: MouseEvent) => {
|
const onMouseMove = (e: MouseEvent) => {
|
||||||
if (document.pointerLockElement !== canvas) return;
|
if (document.pointerLockElement !== canvas) return;
|
||||||
mouseRef.current.x += e.movementX;
|
mouseRef.current.x += e.movementX;
|
||||||
|
|
|
||||||
|
|
@ -63,13 +63,12 @@ export const ObjectViewInternal = function ({ object, objectType, ref, ...props
|
||||||
return reaction(
|
return reaction(
|
||||||
() => gameObj.pendingActions.impulse,
|
() => gameObj.pendingActions.impulse,
|
||||||
(impulse) => {
|
(impulse) => {
|
||||||
if (!impulse) return;
|
if (!impulse || !rbRef.current)
|
||||||
if (!rbRef.current) { console.warn('applyImpulse: rbRef is null for', gameObj.id); return; }
|
return;
|
||||||
|
|
||||||
let { direction, amplitude } = impulse;
|
let { direction, amplitude } = impulse;
|
||||||
amplitude *= 100;
|
amplitude *= 100;
|
||||||
const v = { x: direction[0] * amplitude, y: direction[1] * amplitude, z: direction[2] * amplitude };
|
const v = { x: direction[0] * amplitude, y: direction[1] * amplitude, z: direction[2] * amplitude };
|
||||||
console.log('applyImpulse', gameObj.id, v, 'bodyType', rbRef.current.bodyType());
|
|
||||||
rbRef.current.applyImpulse(v, true);
|
rbRef.current.applyImpulse(v, true);
|
||||||
runInAction(() => {
|
runInAction(() => {
|
||||||
gameObj.pendingActions.impulse = undefined;
|
gameObj.pendingActions.impulse = undefined;
|
||||||
|
|
|
||||||
|
|
@ -29,7 +29,6 @@ export class GameEventBus {
|
||||||
|
|
||||||
emit(event: string, context: GameEventContext): void {
|
emit(event: string, context: GameEventContext): void {
|
||||||
console.log('emitting ' + event);
|
console.log('emitting ' + event);
|
||||||
console.log(Array.from(this.handlers.entries()));
|
|
||||||
this.handlers.get(event)
|
this.handlers.get(event)
|
||||||
?.forEach((handler) => handler(context));
|
?.forEach((handler) => handler(context));
|
||||||
}
|
}
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue