SlideShare a Scribd company logo
Pathfinding in games
Hi,
This is Adrian
I am here because I love to build games and also
to give presentations. Today’s is about...
Pathfinding
in games
Our goal
Reach a target as well as possible.
Artificial intelligence
Non-player character (FPS)
Armies of units (RTS)
Enemies (Tower Defense)
Use cases
Player exploration
Objective display
GPS (Racing)
RTS Starcraft 2
Racing Test Drive Unlimited 2
RPG Mass Effect 2
Get objec
positio
Basic repetitive procedure
Close object
to target
Estimate
distance
to target
Get object
positione object
o target
1.
Space representation
Data structures
Grid
Each cell is denoted by its row and column.
1, 1 1, 2 1, 3 1, 4 1, 5 1, 6 1, 7
2, 1 2, 2 2, 3 2, 4 2, 5 2, 6 2, 7
3, 1 3, 2 3, 3 3, 4 3, 5 3, 6 3, 7
Graph
Node are connected through edges.
1
3
2
6
5
8
4
7
Convex polygons
Convex = all segments with extremities inside lie inside.
2.
Space manipulation
Algorithms
Random backstepping
Take one step in the direction of
the target. Avoid obstacles by
taking a step back.
Simple algorithms
Obstacle tracing
Similar to random
backstepping, calculates the
collision before it happens.
Advanced algorithms
◆ Breadth-first search (BFS)
◆ Depth-first search (DFS)
◆ Best-first search
◆ Dijkstra’s algorithm
◆ A* algorithm
BFS vs DFS
BFS is wide; DFS is deep.
Worst-case
space complexity
Worst-case
time complexity
Implementation
BFS vs DFS
Small: linear in the length
of the current path.
Large: linear in the area of
the explored surface, as it
explores useless paths.
By using a first-in,
first-out (FIFO) data
structure, e.g., a stack.
DFS
Large: linear in the
perimeter of the explored
surface.
Small: quadratic in the
length of the minimum
path.
By using a last-in, first out
(LIFO) data structure, e.g.,
a queue.
BFS
Dijkstra’s algorithm
◆ Solves the single-source shortest path problem.
◆ Invented by Edsger Dijkstra, Turing award winner.
◆ Used in many games for efficient pathfinding.
◆ More efficient than BFS and DFS in terms of time.
◆ More complex in implementation too.
Dijkstra pseudocode
◆ Start with two sets of graph nodes S and T.
◆ S contains the source node and T all others.
While the target node is not in S, do:
◆ Find the node in T that is closest to a node in S.
◆ Move that node from T to S.
◆ Relax the edges from the node to T.
Dijkstra efficiency
◆ To find the closest node, one can use an efficient data
structure, such as a simple heap, to answer queries for
the minimum in a totally-ordered set.
◆ Its operations take worst-case O(n) time, where n is the
number of nodes. With a simple heap, the worst-case
time complexity is O(m ⨉ log n), where m is the number of
edges.
◆ By using Fibonacci heaps, one can reduce the time
complexity down to O(m + n ⨉ log n), as m >> n.
A* algorithm
◆ A “combination” of BFS and Dijkstra.
◆ Does not use exact distances between nodes.
◆ Estimates the distance by using a heuristic.
◆ The heuristic should not overestimate the distance.
Possible heuristics:
◆ Manhattan distance - go straight, no diagonals.
◆ Diagonal distance - go only 45 deg. diagonals.
◆ Euclidean distance - distance in the plane.
A* traversal
The A* will visit the heuristically closest nodes to the target.
3.
Dynamic changes
What about updates on the world?
Distance recalculation
Opportunities:
◆ With every nth iteration of the algorithm.
◆ When the processor is idle.
◆ When a unit reaches a waypoint or a corner.
◆ When the “near world” has changed.
Challenges:
◆ Previously computed data is thrown away.
◆ Can be show for large maps.
Path splice
Main idea:
◆ Splice the large path into smaller
paths.
◆ Only recalculate one or more of
the smaller paths.
◆ Handle the coordination of
multiple units - see image.
Challenges:
◆ Responds poorly to large changes.
Region partition
Main idea:
◆ Partition the map into regions.
◆ Each unit depends of a
specific region.
◆ Propagate a change only
within the region.
Challenges:
◆ Responds badly to large
changes - see image.
Obstacle prediction
Main idea:
◆ Incorporate heuristics that
predict how obstacles will move in
the future - see image.
Challenge:
◆ Depending on the game, the move
may be easy, hard, or impossible
to predict.
4.
Multiple units
How can we coordinate them?
Individual movement
Algorithm:
◆ Find the center of a set of units.
◆ Compute the path from the center
to the target.
◆ Move each individual unit in
parallel, along the path - see
image.
Coordinated movement
Algorithm:
◆ Identify a leader among the units.
◆ Compute the path from the leader
to the target.
◆ Move the leader along the path.
◆ Make the other units flock around
the leader unit - see image.
Thank you.
Any questions?
You can find me at @dumitrix

More Related Content

PDF
Introduction to Game Development.pdf
PPTX
MD5 ALGORITHM.pptx
PDF
User guide lego mindstorms ev3 10 all enus (2)
PDF
CNS - Unit - 4 - Public Key Cryptosystem
PDF
Basic blocks and flow graph in Compiler Construction
PPTX
Transposition Cipher
PDF
Data Structures Through C-Yashavant Kanetkar (1).pdf
PPTX
A* algorithm
Introduction to Game Development.pdf
MD5 ALGORITHM.pptx
User guide lego mindstorms ev3 10 all enus (2)
CNS - Unit - 4 - Public Key Cryptosystem
Basic blocks and flow graph in Compiler Construction
Transposition Cipher
Data Structures Through C-Yashavant Kanetkar (1).pdf
A* algorithm

What's hot (20)

PDF
Lattice Cryptography
PPTX
Data Structure and Algorithms.pptx
PPTX
steganography
PPT
Digital Signature Recognition using RSA Algorithm
PPT
Elliptical curve cryptography
PDF
COMPILER DESIGN- Syntax Directed Translation
PPTX
Introduction to Basics of Python
PPT
Intruders and Viruses in Network Security NS9
PPTX
Debugging Python with Pdb!
PPTX
Cryptography & Steganography
PPTX
C language
PPT
Ll(1) Parser in Compilers
PDF
Parallel sorting Algorithms
PDF
Developing AR and VR Experiences with Unity
PPTX
NumPy.pptx
PDF
Chapter 6: OPERATIONS ON GRAPHS
PDF
Google Cloud Machine Learning
PDF
Lab report for Prolog program in artificial intelligence.
PPT
Dinive conquer algorithm
Lattice Cryptography
Data Structure and Algorithms.pptx
steganography
Digital Signature Recognition using RSA Algorithm
Elliptical curve cryptography
COMPILER DESIGN- Syntax Directed Translation
Introduction to Basics of Python
Intruders and Viruses in Network Security NS9
Debugging Python with Pdb!
Cryptography & Steganography
C language
Ll(1) Parser in Compilers
Parallel sorting Algorithms
Developing AR and VR Experiences with Unity
NumPy.pptx
Chapter 6: OPERATIONS ON GRAPHS
Google Cloud Machine Learning
Lab report for Prolog program in artificial intelligence.
Dinive conquer algorithm
Ad

Similar to Pathfinding in games (20)

PPT
GDC 2012: Advanced Procedural Rendering in DX11
PPTX
Deixtras Algorithm.pptxdjjdjdjdjddddddddddddddd
PPTX
Mrongraphs acm-sig-2 (1)
PDF
Lecture set 5
PDF
Djikstra’s Algorithm. Approach to shortest path algorithm with greedy method
PDF
The Explanation the Pipeline design strategy.pdf
PDF
Lecture 16 - Dijkstra's Algorithm.pdf
PPTX
Dijkstra's algorithm presentation
PPTX
Deep Learning Tutorial
PDF
Darkonoid
PPTX
dms slide discrete mathematics sem 2 engineering
PPTX
Dijkstra’s Algorithm and Prim’s Algorithm in Graph Theory and Combinatorics
PPTX
Dijkstra’s Algorithm and Prim’s Algorithm in Graph Theory and Combinatorics
PPTX
03 image transformations_i
PPTX
SEARCH METHODS - Backtracking search, Beam search, Bidirectional search and N...
PDF
Lucio marcenaro tue summer_school
PDF
Practical Spherical Harmonics Based PRT Methods
PDF
Analysis of Pathfinding Algorithms
PPT
CS 354 More Graphics Pipeline
PDF
GameProgramming for college students DMAD
GDC 2012: Advanced Procedural Rendering in DX11
Deixtras Algorithm.pptxdjjdjdjdjddddddddddddddd
Mrongraphs acm-sig-2 (1)
Lecture set 5
Djikstra’s Algorithm. Approach to shortest path algorithm with greedy method
The Explanation the Pipeline design strategy.pdf
Lecture 16 - Dijkstra's Algorithm.pdf
Dijkstra's algorithm presentation
Deep Learning Tutorial
Darkonoid
dms slide discrete mathematics sem 2 engineering
Dijkstra’s Algorithm and Prim’s Algorithm in Graph Theory and Combinatorics
Dijkstra’s Algorithm and Prim’s Algorithm in Graph Theory and Combinatorics
03 image transformations_i
SEARCH METHODS - Backtracking search, Beam search, Bidirectional search and N...
Lucio marcenaro tue summer_school
Practical Spherical Harmonics Based PRT Methods
Analysis of Pathfinding Algorithms
CS 354 More Graphics Pipeline
GameProgramming for college students DMAD
Ad

Recently uploaded (20)

PPTX
Digital-Transformation-Roadmap-for-Companies.pptx
PDF
Mobile App Security Testing_ A Comprehensive Guide.pdf
PPTX
ACSFv1EN-58255 AWS Academy Cloud Security Foundations.pptx
PDF
NewMind AI Weekly Chronicles - August'25-Week II
PDF
The Rise and Fall of 3GPP – Time for a Sabbatical?
PPT
“AI and Expert System Decision Support & Business Intelligence Systems”
PDF
Advanced methodologies resolving dimensionality complications for autism neur...
PDF
cuic standard and advanced reporting.pdf
PDF
Spectral efficient network and resource selection model in 5G networks
PDF
Blue Purple Modern Animated Computer Science Presentation.pdf.pdf
PPTX
sap open course for s4hana steps from ECC to s4
PDF
MIND Revenue Release Quarter 2 2025 Press Release
PPTX
A Presentation on Artificial Intelligence
DOCX
The AUB Centre for AI in Media Proposal.docx
PDF
Unlocking AI with Model Context Protocol (MCP)
PDF
7 ChatGPT Prompts to Help You Define Your Ideal Customer Profile.pdf
PPTX
VMware vSphere Foundation How to Sell Presentation-Ver1.4-2-14-2024.pptx
PDF
Build a system with the filesystem maintained by OSTree @ COSCUP 2025
PDF
Encapsulation_ Review paper, used for researhc scholars
PDF
Per capita expenditure prediction using model stacking based on satellite ima...
Digital-Transformation-Roadmap-for-Companies.pptx
Mobile App Security Testing_ A Comprehensive Guide.pdf
ACSFv1EN-58255 AWS Academy Cloud Security Foundations.pptx
NewMind AI Weekly Chronicles - August'25-Week II
The Rise and Fall of 3GPP – Time for a Sabbatical?
“AI and Expert System Decision Support & Business Intelligence Systems”
Advanced methodologies resolving dimensionality complications for autism neur...
cuic standard and advanced reporting.pdf
Spectral efficient network and resource selection model in 5G networks
Blue Purple Modern Animated Computer Science Presentation.pdf.pdf
sap open course for s4hana steps from ECC to s4
MIND Revenue Release Quarter 2 2025 Press Release
A Presentation on Artificial Intelligence
The AUB Centre for AI in Media Proposal.docx
Unlocking AI with Model Context Protocol (MCP)
7 ChatGPT Prompts to Help You Define Your Ideal Customer Profile.pdf
VMware vSphere Foundation How to Sell Presentation-Ver1.4-2-14-2024.pptx
Build a system with the filesystem maintained by OSTree @ COSCUP 2025
Encapsulation_ Review paper, used for researhc scholars
Per capita expenditure prediction using model stacking based on satellite ima...

Pathfinding in games

  • 2. Hi, This is Adrian I am here because I love to build games and also to give presentations. Today’s is about...
  • 4. Our goal Reach a target as well as possible.
  • 5. Artificial intelligence Non-player character (FPS) Armies of units (RTS) Enemies (Tower Defense) Use cases Player exploration Objective display GPS (Racing)
  • 7. Racing Test Drive Unlimited 2
  • 9. Get objec positio Basic repetitive procedure Close object to target Estimate distance to target Get object positione object o target
  • 11. Grid Each cell is denoted by its row and column. 1, 1 1, 2 1, 3 1, 4 1, 5 1, 6 1, 7 2, 1 2, 2 2, 3 2, 4 2, 5 2, 6 2, 7 3, 1 3, 2 3, 3 3, 4 3, 5 3, 6 3, 7
  • 12. Graph Node are connected through edges. 1 3 2 6 5 8 4 7
  • 13. Convex polygons Convex = all segments with extremities inside lie inside.
  • 15. Random backstepping Take one step in the direction of the target. Avoid obstacles by taking a step back. Simple algorithms Obstacle tracing Similar to random backstepping, calculates the collision before it happens.
  • 16. Advanced algorithms ◆ Breadth-first search (BFS) ◆ Depth-first search (DFS) ◆ Best-first search ◆ Dijkstra’s algorithm ◆ A* algorithm
  • 17. BFS vs DFS BFS is wide; DFS is deep.
  • 18. Worst-case space complexity Worst-case time complexity Implementation BFS vs DFS Small: linear in the length of the current path. Large: linear in the area of the explored surface, as it explores useless paths. By using a first-in, first-out (FIFO) data structure, e.g., a stack. DFS Large: linear in the perimeter of the explored surface. Small: quadratic in the length of the minimum path. By using a last-in, first out (LIFO) data structure, e.g., a queue. BFS
  • 19. Dijkstra’s algorithm ◆ Solves the single-source shortest path problem. ◆ Invented by Edsger Dijkstra, Turing award winner. ◆ Used in many games for efficient pathfinding. ◆ More efficient than BFS and DFS in terms of time. ◆ More complex in implementation too.
  • 20. Dijkstra pseudocode ◆ Start with two sets of graph nodes S and T. ◆ S contains the source node and T all others. While the target node is not in S, do: ◆ Find the node in T that is closest to a node in S. ◆ Move that node from T to S. ◆ Relax the edges from the node to T.
  • 21. Dijkstra efficiency ◆ To find the closest node, one can use an efficient data structure, such as a simple heap, to answer queries for the minimum in a totally-ordered set. ◆ Its operations take worst-case O(n) time, where n is the number of nodes. With a simple heap, the worst-case time complexity is O(m ⨉ log n), where m is the number of edges. ◆ By using Fibonacci heaps, one can reduce the time complexity down to O(m + n ⨉ log n), as m >> n.
  • 22. A* algorithm ◆ A “combination” of BFS and Dijkstra. ◆ Does not use exact distances between nodes. ◆ Estimates the distance by using a heuristic. ◆ The heuristic should not overestimate the distance. Possible heuristics: ◆ Manhattan distance - go straight, no diagonals. ◆ Diagonal distance - go only 45 deg. diagonals. ◆ Euclidean distance - distance in the plane.
  • 23. A* traversal The A* will visit the heuristically closest nodes to the target.
  • 24. 3. Dynamic changes What about updates on the world?
  • 25. Distance recalculation Opportunities: ◆ With every nth iteration of the algorithm. ◆ When the processor is idle. ◆ When a unit reaches a waypoint or a corner. ◆ When the “near world” has changed. Challenges: ◆ Previously computed data is thrown away. ◆ Can be show for large maps.
  • 26. Path splice Main idea: ◆ Splice the large path into smaller paths. ◆ Only recalculate one or more of the smaller paths. ◆ Handle the coordination of multiple units - see image. Challenges: ◆ Responds poorly to large changes.
  • 27. Region partition Main idea: ◆ Partition the map into regions. ◆ Each unit depends of a specific region. ◆ Propagate a change only within the region. Challenges: ◆ Responds badly to large changes - see image.
  • 28. Obstacle prediction Main idea: ◆ Incorporate heuristics that predict how obstacles will move in the future - see image. Challenge: ◆ Depending on the game, the move may be easy, hard, or impossible to predict.
  • 29. 4. Multiple units How can we coordinate them?
  • 30. Individual movement Algorithm: ◆ Find the center of a set of units. ◆ Compute the path from the center to the target. ◆ Move each individual unit in parallel, along the path - see image.
  • 31. Coordinated movement Algorithm: ◆ Identify a leader among the units. ◆ Compute the path from the leader to the target. ◆ Move the leader along the path. ◆ Make the other units flock around the leader unit - see image.
  • 32. Thank you. Any questions? You can find me at @dumitrix