Add gravity-aware digging direction for ants

In side-view mode, ants carrying non-food powder material now bias their
angle upward toward the surface (30% blend). Ants not carrying anything
bias downward (20% blend) when diggable powder material is detected below.
Both biases are subtle so pheromone-following still shapes overall behavior.
This commit is contained in:
Jared Miller 2026-03-11 15:26:48 -04:00
parent 290d27d85f
commit 6b514f338c
Signed by: shmup
GPG key ID: 22B5C6D66A38B06C

View file

@ -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);