CO2301 Games Development 1 Week 11 Pathfinding Considerations - PowerPoint PPT Presentation

1 / 37
About This Presentation
Title:

CO2301 Games Development 1 Week 11 Pathfinding Considerations

Description:

This method is know as interpolation. Interpolation means to take a set of discrete points at given intervals and ... There are many ways to interpolate data. ... – PowerPoint PPT presentation

Number of Views:24
Avg rating:3.0/5.0
Slides: 38
Provided by: gjbel
Category:

less

Transcript and Presenter's Notes

Title: CO2301 Games Development 1 Week 11 Pathfinding Considerations


1
CO2301 - Games Development 1Week 11Pathfinding
Considerations
  • Gareth Bellaby

2
Topics
  • Final comments on algorithms
  • Representations
  • Path Smoothing
  • Maps and Data
  • Reacquiring Waypoints

3
Topic 1
  • Final comments on algorithms

4
Other Search Variants
  • A is good but explore other variants.
  • Iterative Deepening. Developed for depth-first
    but equally applicable to A. Use A but only to
    a pre-set maximum depth (or even pre-determined
    time).
  • Once fully explored, increase the depth of the
    search by one.
  • Carry on the process until the goal is found.
  • Might seem inefficient since nodes are revisited
    but overhead can be negligible.
  • Bidirectional search. Start two simultaneous
    searches from the start and the goal nodes.

5
Matching Algorithm and Game
  • A
  • dynamic terrain, lots of moving obstacles.
  • Dijkstra
  • static terrain, pre-generated.
  • can always reacquire the waypoint so can be used
    if some dynamic obstacles are expected, e.g.
    other entities running around.

6
Matching Algorithm and Game
  • You can use more than one algorithm in the same
    game.
  • Different algorithms can be used at different
    levels of reasoning, e.g. coarse/fine,
    strategic/tactical, etc.
  • There are also pragmatic variants such as
    relaxing the admissability criteria.

7
Efficiency
  • A is at its most inefficient if a path doesn't
    exist.
  • In such a situation it will examine every
    possible location.
  • This may be a common occurrence depending on the
    game, e.g. lots of units moving and the one under
    consideration has its path blocked to the goal.
  • Use a pre-analysis of the map to determine
    whether a path is possible.

8
A efficiency
  • Uses lots of memory, therefore can be
    inefficient.
  • The biggest overhead is the constant allocation
    and deallocation of substantial amounts of
    memory.
  • Instead pre-allocate memory. Use a memory bank of
    nodes.
  • See Rabin, "A speed optimizations", Games Gems,
    for this and other optimisation techniques. The
    book also has several other good pathfinding
    articles.

9
Matching physical reality
  • It may be that you don't have to worry too much
    about the physical reality of the map.
  • Not doing collision detection.
  • Errors are acceptable.
  • Respond to errors if the occur, e.g. use crash
    and turn
  • Store local information. Cache recently found
    paths.
  • Data is cheap. Reduce complex calculations by
    increasing the number of locations.
  • Remember what I've said about dynamic memory.
  • You do have be concerned about cache misses. This
    will be dealt with next year by Laurent.

10
Level of Detail
  • Do a coarse grained map analysis to calculate the
    main movement path. Do a fine grained analysis to
    calculate the precise movement.
  • Do fine grained detailed pathfinding for the
    immediate location.
  • Break a level up into areas. Set up broad paths
    of movement between the areas.

11
Level of Detail
  • Think about the using other representations, e.g.
    columns and queues.
  • Squad movement, e.g. Dawn of War, Total War.
  • If possible delay calculations, e.g. ignore
    unseen objects.

12
Topic 2
  • Representations

13
Map types
  • You have used a square grid with only horizontal
    and vertical movement.
  • Other representations can be used.
  • These representations may be more efficient than
    a square grid because
  • Search through less data since the representation
    is simplified.
  • May help to identify significant locations on the
    map.
  • Use the representation to select significant or
    useful locations, e.g. two identical rooms, but
    one has a good sniping position.

14
Alternatives
  • See Rabin, "A speed optimizations", Games Gems,
    for a discussion about the relative advantages
    and disadvantages.
  • Grid rectangular, hexagonal.
  • Waypoints.

15
Alternatives
  • Regions (polygons, could use the actual polygons
    of the floor). Does not have to be a regular
    pattern. A region could be room or an area on a
    map.
  • Points of visibility (convex points - describes a
    minimal path.

16
Topic 3
  • Path Smoothing

17
Path Smoothing
  • The path generated by the pathfinding algorithms
    are composed of unnatural looking straight lines
    and abrupt turns. This is true whichever
    representation is used.
  • Path Smoothing is about smoothing the path and
    making something more aesthetically pleasing.

18
Smoothing
  • Smoothing is the operation whereby you capture
    the essence of a set of data whilst leaving out
    the noise.
  • Smoothing is carried out by creating a function.
  • Last week you saw a mathematical function. A
    function "in mathematics, is an expression,
    rule, or law that defines a relationship between
    one variable (the independent variable) and
    another variable (the dependent variable)."
    Encyclopædia Britannica
  • So a function takes an input and calculates an
    output according to some mathematical rule or
    operation.

19
Interpolation
  • Set of points. Want to draw a line through them,
    but we want this to be a aesthetically pleasing
    curve.
  • Need to calculate points in between our known
    points. This method is know as interpolation.
  • Interpolation means to take a set of discrete
    points at given intervals and generate the
    continuous function that passes through the
    points.
  • Laurent will do interpolation with you in the
    context of animation.

20
Path Smoothing
  • There are many ways to interpolate data. I will
    introduce a method of generating a curve called
    the Catmull-Rom spline.
  • I will quickly pass over how it does this, but
    essentially you generate tangents based on the
    position of the sample points.
  • For more details see Van Verthe section 9.6 and
    Rabin, "A Aesthetic Optimizations", Games Gems.

21
Catmull-Rom spline
22
Catmull-Rom spline
  • Need four points.
  • The curve is derived for the line between the
    second and third points.
  • The line is calculated as a sequence of discrete
    locations.
  • The calculation is carried out for each component
    of the four points.
  • Bicubic polynomial.

23
Catmull-Rom spline
  • You don't need to derive all of the points of the
    curve.
  • An efficiency gain can be made by using
    predetermined intervals. This allows you to
    pre-calculating the value of t.
  • Quarter interval
  • Half interval
  • Three quarter interval

24
Catmull-Rom spline
  • In order to derive the line between the second
    and third points (the middle) use all four
    points.
  • In order to derive the line between the first and
    second points (the first third) use the first
    points twice, i.e. p1 and p2 are the same.
  • In order to derive the line between the third and
    last points (the last third) use the last points
    twice, i.e. p3 and p4 are the same.

25
Topic 4
  • Maps and Data

26
Grids
  • You could use a stable grid, i.e. one which you
    have pre-prepared and lay down on the map. This
    allows you to work with the map design.
  • However, could move the grid around, i.e. every
    time you pathfind lay a new grid onto the map in
    a different location
  • Obviously sacrifices design, repetition of search
    data, sharing of data, etc.
  • Can bypass map problems because a difficulty with
    one grid may disappear when you lay down a
    different grid.

27
Map design
  • The AI developer should work closely with the
    level designer. This relationship may include the
    artists as well.
  • Change the design of the level to work with the
    AI.
  • Don't include features which are difficult to
    navigate.
  • Convex is better than concave.

28
Map design
29
Map design
30
Map design
31
Map design
32
Map design - encode features
  • Use elements of the scene to improve the AI. For
    example, It is possible to use colours or
    textures to provide information.
  • Whether a location is inside or outside.
  • Where a choke point exists.
  • The best path to take between two points.
  • These don't have to be visible, just usable.

33
Data
  • Use data instead of pathfinding.
  • Data is cheaper than running an search
  • Do good map design
  • Embed information within the world.

34
Topic 5
  • Reacquiring Waypoints

35
Reacquiring Waypoints
  • Entities will almost certainly move off your
    waypoints or grid during the course of a game,
    e.g. due to combat or to go around obstacles.
  • Assume that this is the case and that you will
    need a "reacquire waypoint/grid" routine.
  • This can be an example of the use of level of
    detail in AI.

36
Reacquiring Waypoints
  • Do not have to worry about realism too much
  • Crash and turn can work surprising well.
  • If you want you could employ a local A.
  • However, it does looks poor if an entity moves
    away from its target.

37
Reacquiring Waypoints
  • Do not necessarily return to the current
    movement node.
  • Select the current and the next node in the
    tree.
  • Choose the node closest to the target by
    reference to the direction of movement of the
    nodes.
  • Direction of movement is 1 to 2.
  • If in the green area, move to node 2.
  • If in the beige area, move to node 1.
Write a Comment
User Comments (0)
About PowerShow.com