Slideshare uses cookies to improve functionality and performance, and to provide you with relevant advertising. If you continue browsing the site, you agree to the use of cookies on this website. See our User Agreement and Privacy Policy.

Slideshare uses cookies to improve functionality and performance, and to provide you with relevant advertising. If you continue browsing the site, you agree to the use of cookies on this website. See our Privacy Policy and User Agreement for details.

Successfully reported this slideshow.

Like this presentation? Why not share!

1,599 views

Published on

No Downloads

Total views

1,599

On SlideShare

0

From Embeds

0

Number of Embeds

4

Shares

0

Downloads

68

Comments

0

Likes

1

No embeds

No notes for slide

- 1. INTERACTIVE OBJECTS INGAMING APPLICATIONSBasic principles and practical scenarios in UnityJune 2013Stavros Vassos Sapienza University of Rome, DIAG, Italy vassos@dis.uniroma1.it
- 2. Interactive objects in games2 Pathfinding Part 1: A* heuristic search on a grid Part 2: Examples in Unity Part 3: Beyond the basics Action-based decision making AI Architectures
- 3. Pathfinding3 Preview
- 4. Interactive objects in games4 Pathfinding Part 1: A* heuristic search on a grid Part 2: Examples in Unity Part 3: Beyond the basics Action-based decision making AI Architectures
- 5. Pathfinding5 Find a path that connects two points in the game world
- 6. Pathfinding6 Find a path that connects two points in the game world Fundamental requirement in most video games Traditionally considered as “AI for games” Typically dealt as separate component of the gamethat is used “as a service” by other AI components,e.g., the decision making component of characters
- 7. Pathfinding7 Find a path that connects two points in the game world Fundamental requirement in most video games Traditionally considered as “AI for games” Typically dealt as separate component of the gamethat is used “as a service” by other AI components,e.g., the decision making component of characters More complicated than it looks!
- 8. Pathfinding8 Funny video with bugs by Paul Tozour (2008)youtube link
- 9. Pathfinding: A* heuristic search9 Let’s start with a textbook approach Game-world as a grid, A* heuristic search
- 10. Pathfinding: A* heuristic search10 Let’s start with a textbook approach Using tool from http://www.policyalmanac.org/
- 11. Pathfinding: A* heuristic search11 Let’s start with a textbook approach Game-world as a grid, A* heuristic search Simple forward search Explore until the target is found Open list Possible nodes to visit next Closed list Visited nodes Choose next node using A cost function g(n) – cost so far A heuristic function h(n) – remaining
- 12. Pathfinding: A* heuristic search12 Let’s start with a textbook approach Game-world as a grid, A* heuristic search Open list Possible nodes to visit next Closed list in blue Visited nodes
- 13. Pathfinding: A* heuristic search13 Let’s start with a textbook approach Game-world as a grid, A* heuristic search Open list in green Possible nodes to visit next Closed list Visited nodes
- 14. Pathfinding: A* heuristic search14 Let’s start with a textbook approach Game-world as a grid, A* heuristic search Open list in green Possible nodes to visit next Closed list in blue Visited nodes Here exactly one node isexpanded (i.e., the starting node)
- 15. Pathfinding: A* heuristic search15 Let’s start with a textbook approach Game-world as a grid, A* heuristic search Use f(n) = g(n) + h(n) for eachnode in the open list to pick thenext one to expand f(n) is computed when node n isadded to the open list, whennode n’ is expanded, e.g.: g(n) = g(n’) + 10 if straight g(n) = g(n’) + 14 if diagonal h(n) = manhattan distance to target
- 16. Pathfinding: A* heuristic search16 Estimated remaining cost h(n) guides the search Cost so far g(n) balances wrt weak estimatesg(n) = 0+10h(n) = 80f(n) = 90
- 17. Pathfinding: A* heuristic search17 Manhattan distance: x2-x1 + y2-y1 Here it is an accurate estimate as the example is trivialg(n) = 0+10h(n) = 80f(n) = 90
- 18. Pathfinding: A* heuristic search18 Expanding the node with the minimal value of f(n)..
- 19. Pathfinding: A* heuristic search19 Expanding the node with the minimal value of f(n)..
- 20. Pathfinding: A* heuristic search20 Expanding the node with the minimal value of f(n)..
- 21. Pathfinding: A* heuristic search21 Things become more interesting when there areobstacles in the way
- 22. Pathfinding: A* heuristic search22 What percentage of the search space will beexpanded (i.e., explored) in this case?
- 23. Pathfinding: A* heuristic search23 We expect that the search would go directlytoward the destination expanding only nodes to theright, until it hits the wall and then go toward upand down in parallel Then, as the g(n) cost of each expanded nodeincreases though, it forces the search method to lookback and expand also in the other directions awayfrom the goal This way, following a dead-end for too long isavoided, but also more nodes are explored
- 24. Pathfinding: A* heuristic search24
- 25. Pathfinding: A* heuristic search25
- 26. Pathfinding: A* heuristic search26
- 27. Pathfinding: A* heuristic search27All four nodes are equallypromising
- 28. Pathfinding: A* heuristic search28f(n1) = 54+50 = 104f(n2) = 44+60 = 104
- 29. Pathfinding: A* heuristic search29f(n1) = 54+50 = 104f(n2) = 44+60 = 104But why notf(n1) = 60+50 ?f(n2) = 50+60 ?
- 30. Pathfinding: A* heuristic search30 Some important details What happens when a node is already visited The closed list keeps track about visited nodes Also keeps track of the best way so far to get there When a node n is expanded by node n’, and f(n) isbetter than the value stored in the closed list, then weupdate the f(n) value
- 31. Pathfinding: A* heuristic search31This node is considered both whenthe two other nodes are expanded
- 32. Pathfinding: A* heuristic search32 Some important details What happens when a node is already visited The closed list keeps track about visited nodes Also keeps track of the best way so far to get there When a node n is expanded by node n’, and f(n) isbetter than the value stored in the closed list, then weupdate the f(n) value We also need to update the best path that leads there
- 33. Pathfinding: A* heuristic search33 Keeping track of the best path that leads to a node In general we could store with each node also the paththat takes us there (we will see this in heuristic search A*planning later) Here we just need to store the parent of the node n,i.e., the node n’ that we expanded to get n with thebest f(n) value
- 34. Pathfinding: A* heuristic search34 Keeping track of the best path that leads to a node In general we could store with each node also the paththat takes us there (we will see this in heuristic search A*planning later) Here we just need to store the parent of the node n,i.e., the node n’ that we expanded to get n with thebest f(n) value This is what these little arrows do in the images we saw
- 35. Pathfinding: A* heuristic search35
- 36. Pathfinding: A* heuristic search36
- 37. Pathfinding: A* heuristic search37f(n1) = 58+60 = 118In fact more costly than the otherf(n2) = 10+100 = 110
- 38. Pathfinding: A* heuristic search38f(n1) = 58+60 = 118In fact more costly than the otherf(n2) = 10+100 = 110Put it differently: alot of cost g(n1) hasbeen invested, butthe estimated costh(n1) is not smallenough to make theoverall cost f(n1) thebest promising
- 39. Pathfinding: A* heuristic search39
- 40. Pathfinding: A* heuristic search40
- 41. Pathfinding: A* heuristic search41
- 42. Pathfinding: A* heuristic search42f(n1) = 146h(n2) = 146
- 43. Pathfinding: A* heuristic search43 Important point about A*! Does A* provide the shortest path?
- 44. Pathfinding: A* heuristic search44 Important point about A*! Does A* provide the shortest path? It depends on the heuristic One particular class of heuristics that ensure optimalsolutions are the admissible heuristics These are optimistic heuristics that alwaysunderestimate the remaining cost
- 45. Pathfinding: A* heuristic search45 Important point about A*! Does A* provide the shortest path? It depends on the heuristic One particular class of heuristics that ensure optimalsolutions are the admissible heuristics These are optimistic heuristics that alwaysunderestimate the remaining cost Intuition1: Think of a heuristic that hugely overestimatesthe optimal path and is zero for all other nodes.
- 46. Pathfinding: A* heuristic search46 Important point about A*! Does A* provide the shortest path? It depends on the heuristic One particular class of heuristics that ensure optimalsolutions are the admissible heuristics These are optimistic heuristics that alwaysunderestimate the remaining cost Intuition2: When heuristic is zero for all nodes, the bestnode is based on total cost so the optimal path is found.
- 47. Pathfinding: A* heuristic search47 Important point about A*! Does A* provide the shortest path? It depends on the heuristic One particular class of heuristics that ensure optimalsolutions are the admissible heuristics These are optimistic heuristics that alwaysunderestimate the remaining cost (Understanding heuristics will become very importantwhen we talk about heuristic search A* planning later)
- 48. Pathfinding: A* heuristic search48 Basic options to consider for pathfinding problems Forward/backward/bi-directional search A*/best-first/weighted A*/… Domain-dependent/independent heuristics Manhattan, Chebyshev, Euclidian Heuristics on Amits A* pages Diagonal movement: 4-connected vs 8-connected grid A* playground to try out different combinations http://qiao.github.io/PathFinding.js/visual/
- 49. Pathfinding: A* heuristic search49
- 50. Pathfinding: A* heuristic search50h(n): EuclideanGrid: 4-connected
- 51. Pathfinding: A* heuristic search51h(n): EuclideanGrid: 8-connected
- 52. Pathfinding: A* heuristic search52h(n): ManhattanGrid: 4-connected
- 53. Pathfinding: A* heuristic search53h(n): ManhattanGrid: 8-connected
- 54. Pathfinding: A* heuristic search54 In many cases this is all you need to handlepathfinding in a game (modulo tuning yourimplementation to be efficient) In AAA modern games though, the game-world ismore complicated both in terms of features and interms of size, and tricks (or research) is needed!
- 55. Pathfinding: A* heuristic search55 More complicated game-worlds Different types of terrain different cost Road, path, water, terrain, mud, … Different type of characters different cost/ability Walking units, vehicles, air-units, scouters, … More than one level Stairs, elevators, hills, slopes, … “Nicer” paths are needed! Smoother curves, more “organic”, with variation, … The game-world is huge! Need for memory and CPU efficiency
- 56. Pathfinding: A* heuristic search56 More complicated game-worlds Different types of terrain different cost Different type of characters different cost/ability More than one level “Nicer” paths are needed! The game-world is huge! We can deal with some of these with simple tricks There is a lot of applied and research work! E.g., AI Programming Wisdom book series Also in top AI/Robotics conferences, e.g., AAAI, ICAPS,AIIDE, IROS
- 57. Pathfinding: A* heuristic search57 Commercial game grid-world benchmarks http://www.movingai.com/benchmarks/
- 58. Pathfinding: A* heuristic search58 GPPC: Grid-Based Path Planning Competition http://movingai.com/GPPC/cfp.html Maps Size at most 2048x2048 Static (unchanging) 8-connected Diagonal actions in an optimal path cost sqrt(2)
- 59. Pathfinding: A* heuristic search59 Many neat tricks for efficient/nice pathfinding Alternative game-world representations Better heuristics Beyond A* But first let’s see how this simple grid representationand A* heuristic works in a game setting in Unity
- 60. Pathfinding Part 2: Examples in Unity60

No public clipboards found for this slide

Be the first to comment