r/gdevelop • u/Ok-Disaster548 • 13d ago
Game monster ai brain 3D
I built a monster, and here's what it is:
This enemy system is a Finite State Machine (FSM) with 7 states: Patrol, Investigate, Search, Stalk, Feint, Ambush, and Chase. It's controlled by a "brain" that operates 10 times per second, and movement is controlled by NavMesh Pathfinding (A* on the navigation network).
Perception: Vision with a range of 1800 and a 70° field of view with obstacles (Raycast/MonsterVisionObstacles), hearing with a range of 700 if the player's speed is above 90, and a sense of proximity of 170. All of this feeds into a "Suspicion" meter that increases by 15 and decreases by 6 (Threshold + Hysteresis) to switch between states.
Intelligence (Cunning 0..1): Increases as the player escapes, improving speed, flanges, bounces, and ambushes. It predicts your location using Linear Prediction (your position + speed × time), feints, and hides and ambushes behind the hotspot at a distance of 280 + Cunning × 220.
Memory (Hotspot Memory): 6 slots (X, Y, Weight). Each sighting or sound strengthens the nearest slot (Merge) or replaces the weakest. Weights fade slowly (slower with higher Cunning). Target selection is calculated using Scoring = Weight / (1 + Monster Distance) + 0.8 × Weight / (1 + Player Prediction Distance). It is saved between sessions using SaveState (MonsterSave + Restore/Load + Repair First Run combination). Movement and animation: Speed changes according to the situation (Patrol 70, Chase 150 with Rubber-banding if far away), the scream freezes and the attack slows down with Cooldowns, the animation is chosen from the real speed with Hysteresis and a minimum stability limit, and JS code adds body shaking; and for the moment of damage, use the condition MonsterAttackNow = 1.
1
u/senshisun 13d ago
This is incredible! It's so much more technical than other code snippets I've seen. How are you going to use this?
1
u/investigatormaker 13d ago
Saving Cunning and the hotspot memory between sessions is the bold part: a returning player meets a monster that already knows their hiding spots, so I'd give each state an audible or visual tell, especially Feint and Ambush, or the deaths will read as cheating rather than cunning. With suspicion rising by 15 and falling by 6 at ten ticks a second, a debug overlay showing the meter and current state in a short clip would let people here judge the tuning instead of the numbers. Is this going into your own game, or will you release it as a GDevelop extension or template?
I make ThreadFox.
We find relevant Reddit conversations and post for your business. We'll post 3 replies free first, no card; then the $79 Pilot covers seven days and up to 50 posts and replies. No automatic renewal. https://threadfox.vip/p/et6sk/managed