43
1 CO3301 - Games Development 2 Weeks 19 & 20 Formations Gareth Bellaby

1 CO3301 - Games Development 2 Weeks 19 & 20 Formations Gareth Bellaby

Embed Size (px)

Citation preview

Page 1: 1 CO3301 - Games Development 2 Weeks 19 & 20 Formations Gareth Bellaby

1

CO3301 - Games Development 2Weeks 19 & 20

Formations

CO3301 - Games Development 2Weeks 19 & 20

Formations

Gareth BellabyGareth Bellaby

Page 2: 1 CO3301 - Games Development 2 Weeks 19 & 20 Formations Gareth Bellaby

2

TopicsTopics

1. What is meant by a formation + some types of formation.

2. Formation movement.

3. Unit collisions and movement

Page 3: 1 CO3301 - Games Development 2 Weeks 19 & 20 Formations Gareth Bellaby

3

Topic 1Topic 1

What is meant by a formation + some types of formation.

Page 4: 1 CO3301 - Games Development 2 Weeks 19 & 20 Formations Gareth Bellaby

4

Formations?Formations?

• What is meant by a formation?

• Formation means different things. The approach taken in a game will depend on what the formation is intended to do.

1. A simple grouping together of units.

2. Grouping units together for combat.

3. Military formations.

Page 5: 1 CO3301 - Games Development 2 Weeks 19 & 20 Formations Gareth Bellaby

5

Simple GroupingSimple Grouping

Simple Grouping: grouping individuals together in order to issue a group order.

Individuals may be placed in an aesthetically pleasing pattern but the pattern has no real effect upon the task.

Page 6: 1 CO3301 - Games Development 2 Weeks 19 & 20 Formations Gareth Bellaby

6

Simple GroupingSimple Grouping

Use only a weak relative positioning algorithm, e.g. try to maintain a minimum distance between individuals. However this value is kept flexible. Attempt to move as a cohesive whole.

Obstacle avoidance can be dealt with on a individual basis; so check individuals against the obstacle, not the group. The group is allowed an unlimited ability to deform. Do not stop for stragglers - tlet the stragglers follow at their own pace.

Alternatively, designate a leader and just employ a follow-the-leader algorithm for movement.

Page 7: 1 CO3301 - Games Development 2 Weeks 19 & 20 Formations Gareth Bellaby

7

Grouping for CombatGrouping for Combat

Basic military principle:

Concentration of force for attack.

However note that it is also considered good practice that combat units keep dispersed otherwise. There is also the problem that concentration makes individuals a good target for area attack such as bombing.

Again units may be placed into aesthetically pleasing formations but it is the massing of units which is important not their relative positioning. Many RTS formations are only aesthetic.

Page 8: 1 CO3301 - Games Development 2 Weeks 19 & 20 Formations Gareth Bellaby

8

Military FormationsMilitary Formations

A military formation is an arrangement of people acting as a unit.

These types of formations have a military purpose, not an aesthetic one.

Formations are a tactic. As such they are a response to other tactics and to weapon characteristics.

Page 9: 1 CO3301 - Games Development 2 Weeks 19 & 20 Formations Gareth Bellaby

9

Military FormationsMilitary Formations

Formations have:

• facing: the direction they soldiers face towards)

• flexibility (or alternatively rigidity): how easily they can change their form.

• mobility (some are fast, some are slow or immobile).

• combat efficiency (which almost certainly varies according to the facing).

• cohesion: how easy it is for the individuals to stay together or to stay in contact with one another.

• size.

Page 10: 1 CO3301 - Games Development 2 Weeks 19 & 20 Formations Gareth Bellaby

10

Some considerationsSome considerations• Weapon length - sword, spear, pike.

• Weapon accuracy - muskets were inaccurate, the introduction of rifling increased accuracy.

• Line of Sight - Napoleonic era cannon were placed in front of the soldiers because otherwise they would hit their own people.

• Technology. The military implications may not always be immediately apparent, e.g. stirrups let the rider more easily stay in the saddle and so led to the use of spears and lances on horseback.

Page 11: 1 CO3301 - Games Development 2 Weeks 19 & 20 Formations Gareth Bellaby

11

Line FormationLine Formation

• Has a facing.

• Extends outwards so that it is difficult to flank the unit.

• Maximum frontage and so efficient for combat.

• Loses cohesion when it moves because individuals will be moving over different terrain. Contact is horizontal so facing and positioning difficult to maintain when moving.

Variants:

• Staggered line.

• Multiple ranks.

• Phalanx.

Page 12: 1 CO3301 - Games Development 2 Weeks 19 & 20 Formations Gareth Bellaby

12

ColumnColumn

• Primarily designed for movement.

• Retains cohension when moving. Contact is vertical so only have to follow the person in front. Narrow frontage so can snake inbetween obstacles (inbetween gaps).

• Fragile if attacked.

Page 13: 1 CO3301 - Games Development 2 Weeks 19 & 20 Formations Gareth Bellaby

13

Bounding overwatchBounding overwatch

• More recent - guns.

• Movement and support.

• Two units. One observes, covers and provides support whilst the other moves. The first then stops and they swap roles.

• A safer way to travel.

Page 14: 1 CO3301 - Games Development 2 Weeks 19 & 20 Formations Gareth Bellaby

14

Others...Others...

Depends on type of warfare being modelled:

• Box (Napoleonic infantry vs cavalry)

• Circle (simple way to face every direction).

• Horde.

If you want to explore this further then you need to look at some military history or military theory.

Page 15: 1 CO3301 - Games Development 2 Weeks 19 & 20 Formations Gareth Bellaby

15

Topic 2Topic 2

Formation movement.

Page 16: 1 CO3301 - Games Development 2 Weeks 19 & 20 Formations Gareth Bellaby

16

Positioning individualsPositioning individuals

Simplest method is to describe a rank offset in the x and y directions.

Each individual is then ascribed to a rank position, or given a position offset from another soldier.

Page 17: 1 CO3301 - Games Development 2 Weeks 19 & 20 Formations Gareth Bellaby

17

Movement into positionMovement into positionBest match is computationally expensive, i.e. moving each individual into their closest position.

Instead use an approximate calculation.

• Sort the units based on their minimum distance to the closest position.

• Go through the list and assign each unit to the closest unused position.

Some units will not move to their closest position but a more efficient calculation than best match. Not far different from realistic human behaviour and jostling for position.

Page 18: 1 CO3301 - Games Development 2 Weeks 19 & 20 Formations Gareth Bellaby

18

Unit MovementUnit Movement

• Use vectors.

• Sort the units by start position.

• Draw a vector from each unit to their end position.

• The vectors will not cross.

Page 19: 1 CO3301 - Games Development 2 Weeks 19 & 20 Formations Gareth Bellaby

19

Unit MovementUnit Movement

Units may be able to share pathfinding information.

• Choose a lead unit. Calculate its path. The other units apply their position offset to determine their path. See Pottinger articles given below.

• Flocking is an alternative. As above, choose leader and calculate path but apply a flocking algorithm for the other members of the unit. (Flocking is next weeks lecture).

Page 20: 1 CO3301 - Games Development 2 Weeks 19 & 20 Formations Gareth Bellaby

20

Tactical AwarenessTactical Awareness

Realism - an AI can move units unrealistically well. The AI could coordinate the movement of a line as easily as a column over flat terrain. This would not happen with people because of the difficulty of maintaining unit cohesion, orders, etc.

Movement and military units:

• Military units are vulnerable when they move.

• Military units lose formation integrity when they move.

• Ambushes are always a possibility.

• Choke points undermine formations.

Page 21: 1 CO3301 - Games Development 2 Weeks 19 & 20 Formations Gareth Bellaby

21

Movement ProblemsMovement Problems

• A formation will encounter a problems if part of the formation moves across a different terrain than the rest of the formation, e.g. one wing of the formation moves through woods.

• Units may also have different speeds.

• The differences in the speeds may be caused by the terrain.

Some options:

1) Move at speed of slowest unit. Simple solution. Can be unrealistic and irritating to the player.

Page 22: 1 CO3301 - Games Development 2 Weeks 19 & 20 Formations Gareth Bellaby

22

Movement ProblemsMovement Problems

2) Leave units to move at own speed. Simple solution but an overhead because the units would have to reform at end of the movement. Can be tactically unwise because:

• It disperses individuals, e.g. the units arrive over time (staggered) and each new arrival is destroyed because they are outnumbered, whereas if the arrived together they would have won.

• You may want to guard units, e.g. slow moving artillery which is especially vulnerable while it moves.

Page 23: 1 CO3301 - Games Development 2 Weeks 19 & 20 Formations Gareth Bellaby

23

Movement ProblemsMovement Problems3) Come up with a sensible alternative, for example:

• Speed up slow units and slow fast units;

• Have a regular series of halt points in order to let slow units catch up;

• Let the player make a choice (if player controlled).

• Use tactics, e.g. reconnaissance units in front and on the flank, a column following on for the main units, slow moving with a guard towards back, use of a front-guard and a back-guard.

The detail will depend on the type of game you are developing. Again, it is worthwhile reading some military theory.

Page 24: 1 CO3301 - Games Development 2 Weeks 19 & 20 Formations Gareth Bellaby

24

Problems of SpaceProblems of Space

Much of the same type of analysis can be used when we consider the size of the formation and analyse its movement.

We can attempt to keep formation at the cost of speed, e.g. the formation swings out from an obstacle, using its bounding box for the calculation.

Page 25: 1 CO3301 - Games Development 2 Weeks 19 & 20 Formations Gareth Bellaby

25

Problems of SpaceProblems of Space

Alternatively you could let the formation deform in order to move around the obstacle in a more efficient fashion.

This might be forced upon you in some cases, e.g. if the only way forward is through a gap.

The formation would reform when it had the space to do so.

Page 26: 1 CO3301 - Games Development 2 Weeks 19 & 20 Formations Gareth Bellaby

26

Formation movementFormation movement

Treat the formation as a movement entity in its own right.

Need to keep track of:

• Orientation

• Desired orientation

• State of the formation

Remember that a formation may need to change its facing, e.g. to wheel to a new facing.

Page 27: 1 CO3301 - Games Development 2 Weeks 19 & 20 Formations Gareth Bellaby

27

Deformation and ReformationDeformation and Reformation

It will take time to deform or reform a formation.

You could overcome this by having individuals move quicker into their new positions. Presumably this will be unrealistic and may look bad on screen.

It is realistic for a formation to pause to allow for the changes to occur.

Page 28: 1 CO3301 - Games Development 2 Weeks 19 & 20 Formations Gareth Bellaby

28

Interspersal ProblemInterspersal Problem

Happens when a formation is allowed to move through a region which has obstacles that block the movement of individuals within the formation, e.g. two formations interpenetrating, or a formation moving through a forest.

Can fudge the situation and just slow the whole formation down and perhaps impose other penalties.

Page 29: 1 CO3301 - Games Development 2 Weeks 19 & 20 Formations Gareth Bellaby

29

Interspersal ProblemInterspersal Problem

Alternatively treat as a sequence of individual collisions.

This solution will cause the formation to begin to disperse and ultimately break apart. Fragmentation will depend on the number of obstacles and the length of travel through their space.

A formation will need to pause and reform after this type of movement. This is realistic.

It is also realistic for a group to ultimately loose all cohesion in such situations, or to break into sub-groups.

Page 30: 1 CO3301 - Games Development 2 Weeks 19 & 20 Formations Gareth Bellaby

30

Stacked Canyon ProblemStacked Canyon Problem

Happens when entities meet a long, narrow passage.

Need to recognise when it happens, e.g. lead unit or higher priority unit bumps into lower priority unit, or it is predicted that this will happen.

Page 31: 1 CO3301 - Games Development 2 Weeks 19 & 20 Formations Gareth Bellaby

31

Stacked Canyon ProblemStacked Canyon Problem

Can treat a queuing problem. There are some well understood mathematical treatments of queues and good solutions.

Could use a recursive solution where we examine each unit for being pushed and for pushing until a unit has a clear path out of the passage. At this point we can unwind the recursion and this will identify the units in the correct movement order from front to back.

Alternatively could go the other way around and find the unit which is pushing and not itself being pushed.

Page 32: 1 CO3301 - Games Development 2 Weeks 19 & 20 Formations Gareth Bellaby

32

Topic 3Topic 3

Unit collisions and movement

Page 33: 1 CO3301 - Games Development 2 Weeks 19 & 20 Formations Gareth Bellaby

33

Prediction DifficultiesPrediction Difficulties

• Difficult to avoid unit collisions.

• Predicting behaviour is extremely difficult. Combinatorial explosion again.

• Behaviour prediction can lead to odd behaviour, e.g. several units all converging on a single point: they can become stuck because of indecision, exhibit flip-flopping, etc.

• Probably better to allow for the fact that some collisions will occur and sort them out when they do.

Page 34: 1 CO3301 - Games Development 2 Weeks 19 & 20 Formations Gareth Bellaby

34

Soft collisionsSoft collisions

Use a "soft" collision radius as well as a "hard" collision radius.

• hard radius: collision detection, collisions not allowed.

• soft radius: use just for decisions and movement in order to keep units at a safe distance from one another.

Use sphere-to-sphere collision detection.

Page 35: 1 CO3301 - Games Development 2 Weeks 19 & 20 Formations Gareth Bellaby

35

Flip-floppingFlip-flopping

Do not want units to counter a previous movement decision. This would cause units to flip-flop between two states, e.g. to turn right in order to go around an obstacle, then carry out another check and turn left, and so on.

Solve by keeping a record of the movement decisions or movement states.

Page 36: 1 CO3301 - Games Development 2 Weeks 19 & 20 Formations Gareth Bellaby

36

ObstaclesObstacles

The formation needs to go around obstacles.

Use bounding boxes.

• It may be better to try to keep formation by using rigid bounding boxes.

• Alternatively allow formation to deform and then reform after the obstacle has been navigated.

The approach will depend on the formation, tactical considerations terrain and game requirements.

Page 37: 1 CO3301 - Games Development 2 Weeks 19 & 20 Formations Gareth Bellaby

37

CollisionsCollisions

Can use sampling to determine if a unit will collide along its intended path.

There is a general problem of sampling for collision detection.

The sampling distance must be smaller than the smallest possible unit otherwise a unit could be in between.

Page 38: 1 CO3301 - Games Development 2 Weeks 19 & 20 Formations Gareth Bellaby

38

Line-to-Sphere CollisionsLine-to-Sphere Collisions

Alternatively could treat the movement as a line and use line-to-sphere collision detection.

This would mean that you have to represent the unit location as a line as well as a position + radius.

The line needs two equidistant edges to take account of the units' size.

Page 39: 1 CO3301 - Games Development 2 Weeks 19 & 20 Formations Gareth Bellaby

39

Predicted positionsPredicted positions

Pottinger suggests keeping a list of the predicted positions of the units.

Can be re-used for collision detection purposes. If the calculations are made accurate then (as an optimisation) you can re-use the data for the actual move.

May be best to employ both points and lines.

Use a queue data structure: fixed length list, new (later) elements are added onto one end knocking the old elements off the other end.

Page 40: 1 CO3301 - Games Development 2 Weeks 19 & 20 Formations Gareth Bellaby

40

Predicted collisionsPredicted collisions

• Employ a priority system in order to determine who gets priority.

• The priority scores could be fixed.

• The priority scores could be dynamic using a heuristic to determine a value for each unit.

Page 41: 1 CO3301 - Games Development 2 Weeks 19 & 20 Formations Gareth Bellaby

41

Compound collisionsCompound collisions

• Collisions involving three or more units.

• Simplest solution is to treat them as a series of unit-to-unit collisions probably invoking the priority system to decide which to solve first.

• Solve a unit-to-unit collision and then use the successful unit (the unit that will move into the space) in the next test, and so on until all of the units have been considered.

Page 42: 1 CO3301 - Games Development 2 Weeks 19 & 20 Formations Gareth Bellaby

42

Further readingFurther reading

Steve Rabin, (2003), "Common Game AI Techniques", AI Game Programming Wisdom 2.

Chad Dawson, (2002), "Formations", AI Game Programming Wisdom.

Dave C. Pottinger, (1999), "Coordinated Unit Movement", Game Developer Magazine, Jan. 1999.

http://www.gamasutra.com/features/game_design/19990122/movement_01.htm

Dave C. Pottinger , (1999), "Implementing Coordinated Movement", Game Developer Magazine , Feb. 1999.

http://www.gamasutra.com/features/19990129/implementing_01.htm

Page 43: 1 CO3301 - Games Development 2 Weeks 19 & 20 Formations Gareth Bellaby

43

Further readingFurther reading

Marco Pinter, (2001) "Toward More Realistic Pathfinding",

Gamasutra.

http://www.gamasutra.com/features/20010314/pinter_01.htm

Van Verth, "Formation-Based Pathfinding With Real-World Vehicles"

http://www.essentialmath.com/vanverth00formationbased.pdf