Skillpedia
برمجة عامة6.6k · #13796

game-ai

ما الذي تفعله

تشرح هذه المهارة كيف تقرر شخصيات اللعبة ما تفعله، وكيف تتحرك، وكيف تجد طريقًا حول العوائق. وهي لمطوري الألعاب الذين يبنون أعداء أو حراسًا أو مجموعات من الشخصيات المتحركة.

متى تستخدمها

  • ✓عندما تبني سلوك دورية أو مطاردة أو حراسة للعدو.
  • ✓عندما تحتاج إلى الاختيار بين آلة حالة أو شجرة سلوك أو توجيه لشخصية.
  • ✓عندما يجب أن يجد العدو طريقًا حول الجدران للوصول إلى اللاعب.

رابط المهارة

https://github.com/gamedev-skills/awesome-gamedev-agent-skills/blob/main/skills/disciplines/game-ai/SKILL.md

انسخه والصقه في الذكاء الاصطناعي الذي تستخدمه (Claude أو ChatGPT أو Cursor) واطلب منه اتباع التعليمات.

طريقة الاستخدام

أسهل طريقة: انسخ الرسالة والصقها في الذكاء الاصطناعي الذي تستخدمه. سيقرأ المهارة وينفّذ تعليماتها.

رسالة جاهزة للصق

استخدم هذه المهارة لمساعدتي: https://github.com/gamedev-skills/awesome-gamedev-agent-skills/blob/main/skills/disciplines/game-ai/SKILL.md اقرأ ملف SKILL.md في هذا الرابط ونفّذ تعليماته لمهمتي.
تريد أن يجد الذكاء الاصطناعي مهارات مثل هذه بنفسه؟ثبّت خادم Skillpedia MCP المجاني: سطر واحد، ويبحث في 15,000+ مهارة قبل كل مهمة.ثبّته في دقيقة واحدة →

مثال على ما تطلبه من الذكاء الاصطناعي

“أريد أن يتجول حارسي، ويطاردني عندما يراني، ويعود إلى مكانه عندما أهرب. أي طريقة ذكاء اصطناعي أستعمل؟”

5 مهارات جديدة كل أسبوع. قراءة في دقيقة واحدة.

كيف تعمل

يوصي الوكيل بآلة حالة بسيطة لعدد قليل من الحالات الواضحة، أو بشجرة سلوك لسلوكيات كثيرة مرتبة بالأولوية، أو بالتقييم للاختيارات المتدرجة. ويفصل القرارات والحركة والبحث عن المسار حتى يسهل تغيير كل جزء.

المحتوى التقني (ملف SKILL.md الأصلي)

النص الأصلي من المؤلف، مباشرة من GitHub.

Game AI: decisions, steering, and pathfinding

Build believable NPC behavior from three separable layers: decide (what to do), steer (how to move there), and path (how to route around the map). Keep them decoupled — a behavior tree picks a target, the pathfinder produces waypoints, steering follows them. This skill teaches the engine-neutral algorithms; bind them to your engine via the related skills below.

When to use

  • Use when implementing enemy/NPC logic: patrols, chase/flee, guard states, group movement, or "find a path to the player".
  • Use to choose between an FSM (few clear states), a behavior tree (many reactive behaviors with priorities), or steering (smooth local movement).
  • Use when integrating pathfinding: A* on a grid/graph, or driving an engine navmesh agent.

When not to use: for the engine's concrete navmesh/agent API and baking, use unity-navmesh, unreal-behavior-trees, or Godot's NavigationAgent2D/3D (see that engine skill). For movement/collision feel, use physics-tuning. For spawning waves along lanes, see the tower-defense genre skill.

Core workflow

  1. Pick the decision model by complexity. 2–5 states with obvious transitions → FSM. Many behaviors, priorities, interruption, reuse → behavior tree. Continuous "how strongly do I want each option" → utility scoring.
  2. Separate decision from motion. The decision layer outputs an intent (target position, action). Steering or pathfinding turns intent into motion.
  3. Path on the right graph. Grid tiles, waypoint graph, or a baked navmesh. Fewer nodes = faster A*. Prefer the engine's navmesh for 3D; A* on a grid for tile games.
  4. Steer along the path, not straight to the goal — follow the next waypoint, advancing when close, so agents round corners.
  5. Recompute paths sparingly. Pathfind on a timer or when the goal moves a tile, not every frame. Cache the path; only the waypoint index advances.
  6. Verify by observation. Watch the agent: does it reach the goal, get stuck on corners, oscillate between states? Draw the path and current state on screen while tuning.

Patterns

1. Finite state machine (one state object, explicit transitions)

# Godot 4.7, one class per file.
# state.gd: each state is a small object with enter/update/exit.
class_name State extends RefCounted
func enter(_agent) -> void: pass
func update(_agent, _dt: float) -> State: return null   # return a state to transition
func exit(_agent) -> void: pass

# chase.gd: returns Patrol when the player escapes sight range.
class_name Chase extends State
func update(agent, dt: float) -> State:
    if not agent.can_see(agent.target):
        return Patrol.new()                 # transition by returning the next state
    agent.move_toward(agent.target.position, dt)
    return null                             # null = stay in this state

# enemy.gd: the agent owns `current` and ticks it once per frame.
var current: State = Patrol.new()           # call current.enter(self) in _ready()

func tick(dt: float) -> void:
    var next := current.update(self, dt)
    if next != null:
        current.exit(self)
        next.enter(self)
        current = next

Keep transition logic inside states (or in a table), never as a growing pile of if flags. One state owns one behavior; that is what keeps an FSM readable.

2. Behavior tree tick (composite nodes return a status)

# A node's tick() returns SUCCESS, FAILURE, or RUNNING (still working this frame).
enum Status { SUCCESS, FAILURE, RUNNING }

# Sequence: run children in order; stop at the first non-SUCCESS (logical AND).
func sequence_tick(children, agent, dt) -> int:
    for child in children:
        var s = child.tick(agent, dt)
        if s != Status.SUCCESS:
            return s                 # FAILURE or RUNNING short-circuits the sequence
    return Status.SUCCESS

# Selector: try children until one succeeds or is RUNNING (logical OR / fallback).
func selector_tick(children, agent, dt) -> int:
    for child in children:
        var s = child.tick(agent, dt)
        if s != Status.FAILURE:
            return s                 # SUCCESS or RUNNING stops the search
    return Status.FAILURE

A guard AI reads top-down: Selector[ Sequence[CanSeePlayer?, Chase], Patrol ] — chase if visible, otherwise patrol. See references/behavior-trees.md for leaf nodes, decorators (Inverter, Cooldown), and a

الأسئلة الشائعة

ما التوجيه (steering)؟

هو حركة محلية سلسة، مثل التوجه نحو هدف أو التحرك مع مجموعة.

هل تغطي نظام التنقل في محرك اللعبة؟

واجهة التنقل الخاصة بالمحرك تغطيها مهارات المحرك ذات الصلة، وهذه المهارة تحيل إليها.

هل يدخل A* ضمنها؟

نعم. تغطي المهارة A* على شبكة أو رسم بياني لإيجاد المسارات.

التفاصيل

الوصف الأصلي من المؤلف

Design NPC and enemy decision-making with finite state machines, behavior trees, steering behaviors, and A* pathfinding — engine-neutral algorithms that pair with the detected engine's navigation API. Use when building enemy AI, an FSM or behavior tree, steering/flocking, or pathfinding, or when the user mentions state machine, behavior tree, blackboard, A*, navmesh, seek, or patrol/chase.

repo: gamedev-skills/awesome-gamedev-agent-skills

الشعبية

نجوم GitHub
6.6k
الترتيب
#13796
الترخيص
Apache-2.0
آخر تحديث
28‏/10‏/2026

هل هذه المهارة مفيدة؟

0

سجّل الدخول للتصويت.

التعليقات

  • …

المزيد من المهارات من هذا المستودع

مهارات مشابهة