@@ -357,8 +357,22 @@ class DragModeSystem extends WorldSystem {
357357 private stopDragging ( ) : void {
358358 if ( ! this . _isDragging ) return
359359
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+
360371 if ( this . _dragTarget ?. physicsDisabled ) {
361- World . physicsSystem . enablePhysicsForBody ( this . _dragTarget . bodyId )
372+ World . physicsSystem . enablePhysicsForBody (
373+ this . _dragTarget . bodyId ,
374+ targetSceneObject ?. mechanism . layerReserve ?. layer
375+ )
362376 } else if ( this . _dragTarget ) {
363377 const body = World . physicsSystem . getBody ( this . _dragTarget . bodyId )
364378 if ( body ) {
@@ -386,17 +400,6 @@ class DragModeSystem extends WorldSystem {
386400 }
387401 }
388402
389- let targetSceneObject : MirabufSceneObject | undefined
390- let shouldTransition = true
391-
392- if ( this . _dragTarget ) {
393- const association = World . physicsSystem . getBodyAssociation ( this . _dragTarget . bodyId ) as RigidNodeAssociate
394- targetSceneObject = association ?. sceneObject
395- if ( association ?. isGamePiece ) {
396- shouldTransition = false
397- }
398- }
399-
400403 this . _isDragging = false
401404 this . _dragTarget = undefined
402405
@@ -427,6 +430,9 @@ class DragModeSystem extends WorldSystem {
427430 World . physicsSystem . activateBody ( this . _dragTarget . bodyId )
428431 }
429432
433+ const compensateGravity =
434+ DragModeSystem . DRAG_FORCE_CONSTANTS . GRAVITY_COMPENSATION && ! this . _dragTarget . physicsDisabled
435+
430436 const currentPos = body . GetPosition ( )
431437 const currentPosition = new THREE . Vector3 ( currentPos . GetX ( ) , currentPos . GetY ( ) , currentPos . GetZ ( ) )
432438 const currentRotation = body . GetRotation ( )
@@ -508,7 +514,7 @@ class DragModeSystem extends WorldSystem {
508514 const forceNeeded = velocityError . multiplyScalar ( forceMultiplier )
509515
510516 // Add gravity compensation to counteract downward pull
511- if ( DragModeSystem . DRAG_FORCE_CONSTANTS . GRAVITY_COMPENSATION ) {
517+ if ( compensateGravity ) {
512518 const gravityCompensation = new THREE . Vector3 (
513519 0 ,
514520 mass * DragModeSystem . DRAG_FORCE_CONSTANTS . GRAVITY_MAGNITUDE ,
@@ -558,7 +564,7 @@ class DragModeSystem extends WorldSystem {
558564 )
559565
560566 // Add gravity compensation to prevent falling when stationary
561- if ( DragModeSystem . DRAG_FORCE_CONSTANTS . GRAVITY_COMPENSATION ) {
567+ if ( compensateGravity ) {
562568 const gravityCompensationY = mass * DragModeSystem . DRAG_FORCE_CONSTANTS . GRAVITY_MAGNITUDE
563569 brakingForce . SetY ( brakingForce . GetY ( ) + gravityCompensationY )
564570 }
0 commit comments