@@ -92,7 +92,7 @@ class DragModeSystem extends WorldSystem {
9292 this . handleWheelDuringDrag ( event )
9393 }
9494 }
95- this . _unsubscriber = EventSystem . listen ( "DragModeToggled " , ( { enabled } ) => {
95+ this . _unsubscriber = EventSystem . listen ( "SetDragModeEvent " , ( { enabled } ) => {
9696 this . enabled = enabled
9797 } )
9898 }
@@ -101,6 +101,7 @@ class DragModeSystem extends WorldSystem {
101101 return this . _enabled
102102 }
103103
104+ /** toggle using SetDragModeEvent. Not this */
104105 public set enabled ( enabled : boolean ) {
105106 if ( this . _enabled === enabled ) return
106107
@@ -123,8 +124,6 @@ class DragModeSystem extends WorldSystem {
123124 this . _dragModeStartTime = undefined
124125 }
125126 }
126-
127- EventSystem . dispatch ( "DragModeToggled" , { enabled } )
128127 }
129128
130129 public update ( _deltaT : number ) : void {
@@ -358,8 +357,22 @@ class DragModeSystem extends WorldSystem {
358357 private stopDragging ( ) : void {
359358 if ( ! this . _isDragging ) return
360359
360+ let targetSceneObject : MirabufSceneObject | undefined
361+ let shouldTransition = true
362+
363+ if ( this . _dragTarget ) {
364+ const association = World . physicsSystem . getBodyAssociation ( this . _dragTarget . bodyId ) as RigidNodeAssociate
365+ targetSceneObject = association ?. sceneObject
366+ if ( association ?. isGamePiece ) {
367+ shouldTransition = false
368+ }
369+ }
370+
361371 if ( this . _dragTarget ?. physicsDisabled ) {
362- World . physicsSystem . enablePhysicsForBody ( this . _dragTarget . bodyId )
372+ World . physicsSystem . enablePhysicsForBody (
373+ this . _dragTarget . bodyId ,
374+ targetSceneObject ?. mechanism . layerReserve ?. layer
375+ )
363376 } else if ( this . _dragTarget ) {
364377 const body = World . physicsSystem . getBody ( this . _dragTarget . bodyId )
365378 if ( body ) {
@@ -387,17 +400,6 @@ class DragModeSystem extends WorldSystem {
387400 }
388401 }
389402
390- let targetSceneObject : MirabufSceneObject | undefined
391- let shouldTransition = true
392-
393- if ( this . _dragTarget ) {
394- const association = World . physicsSystem . getBodyAssociation ( this . _dragTarget . bodyId ) as RigidNodeAssociate
395- targetSceneObject = association ?. sceneObject
396- if ( association ?. isGamePiece ) {
397- shouldTransition = false
398- }
399- }
400-
401403 this . _isDragging = false
402404 this . _dragTarget = undefined
403405
@@ -428,6 +430,9 @@ class DragModeSystem extends WorldSystem {
428430 World . physicsSystem . activateBody ( this . _dragTarget . bodyId )
429431 }
430432
433+ const compensateGravity =
434+ DragModeSystem . DRAG_FORCE_CONSTANTS . GRAVITY_COMPENSATION && ! this . _dragTarget . physicsDisabled
435+
431436 const currentPos = body . GetPosition ( )
432437 const currentPosition = new THREE . Vector3 ( currentPos . GetX ( ) , currentPos . GetY ( ) , currentPos . GetZ ( ) )
433438 const currentRotation = body . GetRotation ( )
@@ -509,7 +514,7 @@ class DragModeSystem extends WorldSystem {
509514 const forceNeeded = velocityError . multiplyScalar ( forceMultiplier )
510515
511516 // Add gravity compensation to counteract downward pull
512- if ( DragModeSystem . DRAG_FORCE_CONSTANTS . GRAVITY_COMPENSATION ) {
517+ if ( compensateGravity ) {
513518 const gravityCompensation = new THREE . Vector3 (
514519 0 ,
515520 mass * DragModeSystem . DRAG_FORCE_CONSTANTS . GRAVITY_MAGNITUDE ,
@@ -559,7 +564,7 @@ class DragModeSystem extends WorldSystem {
559564 )
560565
561566 // Add gravity compensation to prevent falling when stationary
562- if ( DragModeSystem . DRAG_FORCE_CONSTANTS . GRAVITY_COMPENSATION ) {
567+ if ( compensateGravity ) {
563568 const gravityCompensationY = mass * DragModeSystem . DRAG_FORCE_CONSTANTS . GRAVITY_MAGNITUDE
564569 brakingForce . SetY ( brakingForce . GetY ( ) + gravityCompensationY )
565570 }
0 commit comments