@@ -358,8 +358,22 @@ class DragModeSystem extends WorldSystem {
358358 private stopDragging ( ) : void {
359359 if ( ! this . _isDragging ) return
360360
361+ let targetSceneObject : MirabufSceneObject | undefined
362+ let shouldTransition = true
363+
364+ if ( this . _dragTarget ) {
365+ const association = World . physicsSystem . getBodyAssociation ( this . _dragTarget . bodyId ) as RigidNodeAssociate
366+ targetSceneObject = association ?. sceneObject
367+ if ( association ?. isGamePiece ) {
368+ shouldTransition = false
369+ }
370+ }
371+
361372 if ( this . _dragTarget ?. physicsDisabled ) {
362- World . physicsSystem . enablePhysicsForBody ( this . _dragTarget . bodyId )
373+ World . physicsSystem . enablePhysicsForBody (
374+ this . _dragTarget . bodyId ,
375+ targetSceneObject ?. mechanism . layerReserve ?. layer
376+ )
363377 } else if ( this . _dragTarget ) {
364378 const body = World . physicsSystem . getBody ( this . _dragTarget . bodyId )
365379 if ( body ) {
@@ -387,17 +401,6 @@ class DragModeSystem extends WorldSystem {
387401 }
388402 }
389403
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-
401404 this . _isDragging = false
402405 this . _dragTarget = undefined
403406
@@ -428,6 +431,9 @@ class DragModeSystem extends WorldSystem {
428431 World . physicsSystem . activateBody ( this . _dragTarget . bodyId )
429432 }
430433
434+ const compensateGravity =
435+ DragModeSystem . DRAG_FORCE_CONSTANTS . GRAVITY_COMPENSATION && ! this . _dragTarget . physicsDisabled
436+
431437 const currentPos = body . GetPosition ( )
432438 const currentPosition = new THREE . Vector3 ( currentPos . GetX ( ) , currentPos . GetY ( ) , currentPos . GetZ ( ) )
433439 const currentRotation = body . GetRotation ( )
@@ -509,7 +515,7 @@ class DragModeSystem extends WorldSystem {
509515 const forceNeeded = velocityError . multiplyScalar ( forceMultiplier )
510516
511517 // Add gravity compensation to counteract downward pull
512- if ( DragModeSystem . DRAG_FORCE_CONSTANTS . GRAVITY_COMPENSATION ) {
518+ if ( compensateGravity ) {
513519 const gravityCompensation = new THREE . Vector3 (
514520 0 ,
515521 mass * DragModeSystem . DRAG_FORCE_CONSTANTS . GRAVITY_MAGNITUDE ,
@@ -559,7 +565,7 @@ class DragModeSystem extends WorldSystem {
559565 )
560566
561567 // Add gravity compensation to prevent falling when stationary
562- if ( DragModeSystem . DRAG_FORCE_CONSTANTS . GRAVITY_COMPENSATION ) {
568+ if ( compensateGravity ) {
563569 const gravityCompensationY = mass * DragModeSystem . DRAG_FORCE_CONSTANTS . GRAVITY_MAGNITUDE
564570 brakingForce . SetY ( brakingForce . GetY ( ) + gravityCompensationY )
565571 }
0 commit comments