diff --git a/src/shaders/antsCompute.frag b/src/shaders/antsCompute.frag index a377a55..5f772e1 100644 --- a/src/shaders/antsCompute.frag +++ b/src/shaders/antsCompute.frag @@ -180,6 +180,38 @@ void main() { } if (!movementProcessed) { + #if VIEW_MODE_SIDE + // vertical bias for digging behavior + if (isCarrying == 1. && int(cargoMaterialId) != MAT_FOOD) { + // carrying powder: bias upward toward surface + float upwardBias = PI * 0.5; // straight up + float angleDiff = upwardBias - angle; + // normalize to [-PI, PI] + angleDiff = mod(angleDiff + PI, 2.0 * PI) - PI; + // gentle steering toward up (blend 30% toward upward) + angle += angleDiff * 0.3; + } else if (isCarrying == 0.) { + // not carrying: check if surrounded by diggable material + // if so, prefer downward movement + float cellMatId = texture(tWorld, roundUvToCellCenter(pos)).x; + vec4 props = texelFetch(uMaterialProps, ivec2(int(cellMatId), 0), 0); + + // check cell below for diggable material + vec2 belowUv = roundUvToCellCenter(pos - vec2(0., cellSize)); + float belowMat = texture(tWorld, belowUv).x; + vec4 belowProps = texelFetch(uMaterialProps, ivec2(int(belowMat), 0), 0); + + if (belowProps.r == BEHAVIOR_POWDER && belowProps.b <= ANT_CARRY_STRENGTH) { + // diggable material below — bias downward + float downwardBias = -PI * 0.5; // straight down + float angleDiff = downwardBias - angle; + angleDiff = mod(angleDiff + PI, 2.0 * PI) - PI; + // gentle steering toward down (20% blend) + angle += angleDiff * 0.2; + } + } + #endif + float noise2 = rand(vUv * 1000. + fract(uTime / 1000.) + 0.2); float sampleAhead = smell(applyOffsetToPos(pos, vec2(cos(angle), sin(angle)) * sampleDistance), isCarrying);