@@ -16,17 +16,23 @@ protected override void ApplyPatches()
16
16
private static void CollisionEnhancer_FixedUpdate_Override ( CollisionEnhancer __instance )
17
17
{
18
18
Part part = __instance . part ;
19
+ bool hasPart = part . IsNotNullOrDestroyed ( ) ;
19
20
20
- if ( part . IsNullOrDestroyed ( ) || part . partTransform . IsNullOrDestroyed ( ) )
21
- return ;
22
-
23
- Vector3 position = part . partTransform . position ;
21
+ Vector3 position ;
22
+ if ( hasPart )
23
+ {
24
+ position = part . partTransform . position ;
24
25
25
- if ( part . packed )
26
+ if ( part . packed )
27
+ {
28
+ __instance . lastPos = position ;
29
+ __instance . wasPacked = true ;
30
+ return ;
31
+ }
32
+ }
33
+ else
26
34
{
27
- __instance . lastPos = position ;
28
- __instance . wasPacked = true ;
29
- return ;
35
+ position = __instance . transform . position ;
30
36
}
31
37
32
38
if ( __instance . framesToSkip > 0 )
@@ -36,7 +42,7 @@ private static void CollisionEnhancer_FixedUpdate_Override(CollisionEnhancer __i
36
42
return ;
37
43
}
38
44
39
- if ( part . vessel . IsNullOrDestroyed ( ) || part . vessel . heightFromTerrain > 1000f )
45
+ if ( hasPart && ( part . vessel . IsNullOrDestroyed ( ) || part . vessel . heightFromTerrain > 1000f ) )
40
46
{
41
47
__instance . lastPos = position ;
42
48
return ;
@@ -49,14 +55,15 @@ private static void CollisionEnhancer_FixedUpdate_Override(CollisionEnhancer __i
49
55
50
56
CollisionEnhancerBehaviour mode = __instance . OnTerrainPunchThrough ;
51
57
52
- if ( mode < CollisionEnhancerBehaviour . COLLIDE // only handle EXPLODE, TRANSLATE and TRANSLATE_BACK_SPLAT
58
+ if ( mode < CollisionEnhancerBehaviour . COLLIDE // only handle EXPLODE, TRANSLATE_BACK and TRANSLATE_BACK_SPLAT
53
59
&& ! CollisionEnhancer . bypass
54
- && part . State != PartStates . DEAD
60
+ && ( ! hasPart || part . State != PartStates . DEAD )
55
61
&& ( __instance . lastPos - position ) . sqrMagnitude > CollisionEnhancer . minDistSqr
56
62
&& Physics . Linecast ( __instance . lastPos , position , out RaycastHit hit , 32768 , QueryTriggerInteraction . Ignore ) ) // linecast against the "LocalScenery" layer
57
63
{
58
64
Vector3 rbVelocity = __instance . rb . velocity ;
59
- Debug . Log ( $ "[F: { Time . frameCount } ]: [{ __instance . name } ] Collision Enhancer Punch Through - vel: { rbVelocity . magnitude } ") ;
65
+ string objectName = hasPart ? part . partInfo ? . name ?? __instance . name : __instance . name ;
66
+ Debug . Log ( $ "[Collision Enhancer] { mode . ToString ( ) } on \" { objectName } \" (vel: { rbVelocity . magnitude . ToString ( "F0" ) } )") ;
60
67
61
68
if ( mode == CollisionEnhancerBehaviour . EXPLODE
62
69
&& ! CheatOptions . NoCrashDamage
@@ -86,8 +93,12 @@ private static void CollisionEnhancer_FixedUpdate_Override(CollisionEnhancer __i
86
93
__instance . rb . velocity = newVel . IsInvalid ( ) ? Vector3 . zero : newVel ;
87
94
}
88
95
}
89
- GameEvents . OnCollisionEnhancerHit . Fire ( part , hit ) ;
90
- GameEvents . onPartExplodeGroundCollision . Fire ( part ) ;
96
+
97
+ if ( hasPart )
98
+ {
99
+ GameEvents . OnCollisionEnhancerHit . Fire ( part , hit ) ;
100
+ GameEvents . onPartExplodeGroundCollision . Fire ( part ) ;
101
+ }
91
102
}
92
103
93
104
__instance . lastPos = position ;
0 commit comments