Ai part 1


Published on

Steering behaviors and pathfinding, by Dan Sosnowski

Published in: Education, Technology
  • Be the first to comment

  • Be the first to like this

No Downloads
Total views
On SlideShare
From Embeds
Number of Embeds
Embeds 0
No embeds

No notes for slide
  • Steering behaviors as low level movement logic, often used in combination with each other to create interesting behaviors for autonomous agents.A few weeks ago one of the AI programmers on Castlevania: LoS was talking about, well, AI in LoS. I found it interesting when he mentioned the birds on the crow witch was mostly a flocking behavior, with some tweaksFlocks of bats and herds of penguins in Batman Returns, movement of orc armies in Lord of the RingsWhile you won’t use everyone in every game, having an understanding of them and saving them in your back pocket can be extremely useful.
  • It would be great to have a direct path to follow to get there, wouldn’t it? What do we need to accomplish this? First, we need a large
  • If your graph isn’t going to utilize special terrain
  • Ai part 1

    1. 1. INTRO TO INTELLIGENT ANDAUTONOMOUS AGENTSSteering behaviors and pathfinding
    2. 2. Game AI What we’re covering today  And what we’re not How AI can improve your games Autonomous agents
    3. 3. Steering Behaviors What they are When they’re used  Quite often   Movies Let’s try some out!
    4. 4. Seek Move entity from current position to target position as quickly as possible
    5. 5. Our entity is the triangle. How do we get to thetarget?
    6. 6. Desired velocity = target.position - myPosition
    7. 7. You can get a vector pointing from A to B by B - A
    8. 8. Don’t worry aboutovershooting, it’ll becorrected
    9. 9. Other steering behaviors Arrive Obstacle Avoidance Make sure we don’t have a force that’s too big!
    10. 10. Using SBs in your Entities ChasePlayer State  Obstacle avoidance, Pursue or Seek Idle State  Wander, maybe flocking? Sheep  Flocking, Wander, Obstacle Avoidance, Evade
    11. 11. Steering behaviors ftw :?
    12. 12. Wouldn’t this be lovely? Well then, let’s find a path
    13. 13. A graph of points! (navigation graph)
    14. 14. Building a Nav Graph Goal: A list of nodes and edges What is needed:  Start point, cast distance, interval  (optional)Max number of nodes
    15. 15. Data StructuresGraphNode GraphEdgeVector3 position GraphNode fromNodeGraphEdge[4] edges GraphFrom toNode (Float weight)
    16. 16. List<GraphNodes> NodesFor ( i = 1; i <= xCastDistance; ++i) For (j = 1; j <= zCastDistance; ++j) { cast a ray downward from above for each potential neighbor node (i.e. (curX + invertal, curZ), (curX, curZ + interval), etc.) if raycast hit the ground { new GraphNode(GraphNode(Raycast hit point)) if we haven’t already found this node { Add new graph node to Nodes } (calculate edge cost) new GraphEdge(current node, new graph node, cost)) Add new graph edge to the current node’s Edge list }
    17. 17. Start from initial position, start casting out!
    18. 18. What happens when node cast hits out of bounds?
    19. 19. New position
    20. 20. Nothing new, just adding another node/edge
    21. 21. :o A box!Hit an object not tagged ground, skip it, keep moving
    22. 22. :OOOOO But we already processed that node!Result depends on algorithm implementation. Easy route (the way the pseudo code wassetup) is to have each node responsible for itself. So in our case add the edge and ignorethe node.
    23. 23. Improvements Worth Mentioning Reducing node density Indexing GraphNodes and GraphEdges
    24. 24. Data Structures for IndexingGraphNode GraphEdgeint index int fromNodeIndexVector3 position int toNodeIndexGraphEdge[4] mEdges float weight Instead of storing the GraphNodes that a GraphEdge is connected to, we store the index of each GraphNode, so we’re not storing a GraphNode twice
    25. 25. Take a look at that graph
    26. 26. Search Algorithms Depth-first search Breadth-first search Dijkstra’s algorithm A* (aka Dijkstra++)  ^ yahtzee
    27. 27. Dijkstra’s Algorithm Usable with weighted graphs. Graphs without weight can be processed by assuming edges of equal weight Guaranteed to find shortest path, if it exists. Implementation  Examine nodes on our search frontier, find the one with the smallest total weight, and add it to our path and keep going
    28. 28. Picture from “Programming Game AI by Example” by Mat Buckland
    29. 29. Picture from “Programming Game AI by Example” by Mat Buckland
    30. 30. A* Dijkstra with an additional weight factor (heuristic)  Heuristic: Making a decision based on some knowledge There’s something troublesome in the Dijsktra implementation that seems like it would be an easy fix
    31. 31. We know where our target is, so let’s approximate the cost from the nodes we are looking at to the target and factor that into what we chooseIn this case, Euclidean distance
    32. 32. Manhattan Distance
    33. 33. ResultsPicture from “Programming Game AI by Example” by Mat Buckland
    34. 34. Picture from “Programming Game AI by Example” by Mat Buckland
    35. 35. Review Steering behaviors Navigation graphs Search algorithms So how do they work together?  You have a point on the graph you want to reach.  You find a sequence of nodes to follow.  Use steering behaviors to get from point to point, and create interesting behavior on the way
    36. 36. Next time… Organizing these lower level decisions into functional, autonomous agents (in a smart, extendable, debug-friendly way ) Questions?(can someone let Jordan know he can wake up now? kthx)