Chasing, Evading, Intercepting, Pattern Movements

Slides:



Advertisements
Similar presentations
Graphics Primitives: line
Advertisements

7.2. AI E NGINE AND S TEERING B EHAVIOUR I Design of an AI Engine and introduction to steering in game AI.
7.3. S TEERING B EHAVIOUR II Steering behaviours in game AI.
Section 3-1 to 3-2, 3-5 Drawing Lines Some of the material in these slides may have been adapted from university of Virginia, MIT, and Åbo Akademi University.
Line Drawing Algorithms. Rasterization-Process of determining which pixels give the best approximation to a desired line on the screen. Scan Conversion-Digitizing.
Flocking and more.  NPC groups can move in cohesive groups not just independently ◦ Meadow of sheep grazing? ◦ Hunting flock of birds? ◦ Ants? Bees?
Pathfinding Basic Methods.
Fronts and Coriolis. Fronts Fronts - boundaries between air masses of different temperature. –If warm air is moving toward cold air, it is a “warm front”.
Behavioral animation CSE 3541 Matt Boggus. Material recap and trajectory Geometric – Artist specifies translation and rotation over time Physically based.
Flocking References: xxx.
Math / Physics 101 GAM 376 Robin Burke Winter 2008.
Multiagent Probabilistic Smart Terrain Dr. John R. Sullins Youngstown State University.
Artificial Intelligence in Game Design Intelligent Decision Making and Decision Trees.
Artificial Intelligence in Game Design Introduction to Learning.
1 AI for Computer Game Developers Finite state machines Path finding and waypoints A-Star path finding.
CS 4730 Game AI CS 4730 – Computer Game Design Some slides courtesy Tiffany Barnes, NCSU.
Search and Escape in “The Snorks World” Guillaume Poncin Gregory Kron Monday, June 9 th 2003.
Artificial Intelligence in Game Design Probabilistic Finite State Machines.
CS274 Spring 01 Lecture 5 Copyright © Mark Meyer Lecture V Higher Level Motion Control CS274: Computer Animation and Simulation.
Intelligent Pac-Man Ghost AI
Games Programming III (TGP2281) – T1, 2010/2011 Movement AI John See 19, 26 Nov 2010.
SuperCorners. Problem The Corners sample robot has a simple strategy: first, move into a corner of the arena, and second sweep the gun back and forth.
SOURCE 2006 Presentation by Luke Arntson Game Programming Optimization.
MOTION.
1 CO Games Development 1 Week 5 Deriving a "look at" function + Graph Theory Gareth Bellaby.
Scan Conversion. Also known as rasterization In our programs objects are represented symbolically –3D coordinates representing an object’s position –Attributes.
Artificial Intelligence in Game Design Problems and Goals.
MOTION. Chapter Four: MotionMotion  4.1 Position, Speed and Velocity  4.2 Graphs of Motion  4.3 Acceleration.
Motion  1 Position, Speed and Velocity  2 Graphs of Motion  3 Acceleration.
Artificial Intelligence in Game Design
Chapter 5 Trajectory Planning 5.1 INTRODUCTION In this chapters …….  Path and trajectory planning means the way that a robot is moved from one location.
Chapter 5 Trajectory Planning 5.1 INTRODUCTION In this chapters …….  Path and trajectory planning means the way that a robot is moved from one location.
For games. 1. Control  Controllers for robotic applications.  Robot’s sensory system provides inputs and output sends the responses to the robot’s motor.
LAWS OF MOTION Biomechanics.
Math / Physics 101 GAM 376 Robin Burke Fall 2006.
Mark Nelson Movement and physics Fall 2013
CGMB214: Introduction to Computer Graphics
 A line segment in a scene is defined by the coordinate positions of the line end-points x y (2, 2) (7, 5)
Chapter 1 Introduction to Game AI April 11,
Artificial Intelligence in Game Design Dynamic Path Planning Algorithms.
Chasing, Evading, Intercepting, Pattern Movements
Games Development 2 Entity Update & Rendering CO3301 Week 2, Part 1.
Kinematics in Two Dimensions. Section 1: Adding Vectors Graphically.
Computational theory techniques in interactive video games.
Basic Steering of Game Agents Featuring Guest professors Stephen Sheneman & Michael Wilkens 1.
Distance and Displacement Speed and Velocity Acceleration.
F.E.A.R. Game AI Evaluation by Robert Rak. What is F.E.A.R. ? FEAR is a First Person Shooter game Player takes on the role of an elite strike force team.
REFERENCES: FLOCKING.
GEOMETRY AND LINE GENERATION Geometry and Line Generation Chapter 2.
School of Systems, Engineering, University of Reading rkala.99k.org April, 2013 Motion Planning for Multiple Autonomous Vehicles Rahul Kala Logic Based.
Dr Nick Mitchell (Room CM 224)
Decision Making and Branching (cont.)
CSCI 4310 Lecture 5: Steering Behaviors in Raven.
Artificial Intelligence in Game Design Lecture 20: Hill Climbing and N-Grams.
MOTION. Chapter Four: Motion  4.1 Position, Speed and Velocity  4.2 Graphs of Motion  4.3 Acceleration.
Motion Position, Speed and Velocity Graphs of Motion Acceleration.
Chapter 2: Describing Motion in 1-D. Frame of Reference Whether or not you are moving depends on your point-of-view. From inside the box car, the woman.
Computer Graphics CC416 Lecture 04: Bresenham Line Algorithm & Mid-point circle algorithm Dr. Manal Helal – Fall 2014.
CS 134 Video Game “AI”.
MOTION.
Winning Strategy in Programming Game Robocode
Chapter Four: Motion 4.1 Position, Speed and Velocity
Lesson Objectives Aims Understand the following “standard algorithms”:
CIS 488/588 Bruce R. Maxim UM-Dearborn
Navigation In Dynamic Environment
CIS 488/588 Bruce R. Maxim UM-Dearborn
CIS 488/588 Bruce R. Maxim UM-Dearborn
Steering behaviours in game AI
MOTION.
Animation Translation.
Presentation transcript:

Chasing, Evading, Intercepting, Pattern Movements Basic Movement AI Chasing, Evading, Intercepting, Pattern Movements

Movement AI Movement – Ubiquitous behavior found in many games Chasing and Evading – the most basic movement AI that can be implemented on NPCs

Chasing & Evading 2 parts Decision to initiate a chase or evade Effecting the chase or evade Sometimes, a 3rd part, to avoid obstacles while chasing and evading is required, but that can be considered separately 1st part – decision making Focus on 2nd part – concerns the action itself, to chase and evade

Basic method Simplest method: Update NPC coordinates through each game loop to Decrease the distance between NPC and player (chase) Increase the distance between NPC and player (evade) Pays no attention to NPC or player headings (direction of travel) or speeds

More complex methods Positions and velocities (direction of travel) of both NPC and player are considered so that NPC can be moved to intercept the player instead of relentless chasing In short: Predicting where the player will likely to be at in the future, and moving towards that as target

Basic Chasing Pseudocode for Chasing if (npcX > playerX) npcX--; else if (npcX < playerX) npcX++; if (npcY > playerY) npcY--; else if (npcY < playerY) npcY++;

Basic Evading Moving farther, instead of moving closer Pseudocode for Evading if (npcX > playerX) npcX++; else if (npcX < playerX) npcX--; if (npcY > playerY) npcY++; else if (npcY < playerY) npcY--;

Tile-based environment – How? 8-way movement

Tile-based Chase movement Updating difference Continuous environment: x, y coordinates in Cartesian coordinate system (float) Tile-based environment: x, y in tile coordinate system (int.) are columns and rows if (npcCol > playerCol) npcCol--; else if (npcCol < playerCol) npcCol++; if (npcRow > playerRow) npcRow--; else if (npcRow < playerRow) npcRow++;

Tile-based Chase – Any problem?

Line-of-sight Chasing Make NPC take a direct straight-line path towards player Stationary player – straight path Moving player – path is not necessarily straight Note  may not look too bad if game loop constantly updates position, path should appear curved and natural Movements in TBE will appear less smoother than CE due to coarse movement units

L-o-S Chasing in TBE Aesthetic disadvantage of using simple basic chase – although no. of steps are the same Limitation of 8-way movement, no other possible angles Will look really BAD if many NPCs are chasing this way

L-o-S Chasing in TBE Solution: To calculate an intermediate path (closest to a straight line) for the NPC to chase Use a standard line-drawing algorithm – Bresenham’s algorithm Nice thing: Does not draw two adjacent pixels along a line’s shortest axis Path calculation function Calculate and store a series of tiles to be moved to Needs to be called every time player changes position

L-o-S Path in TBE

“Looking At” Rotation Without “Looking At” Rotation Only x and/or y are updated at each time (8-direction) With “Looking At” Rotation Additional rotation steers NPC to look at target and chase in that direction (x1, y1) (x2, y2) (x1, y1) (x2, y2) θ

Thrust and Steering forces Thrust force: pushes object to the front (velocity) Steering force: pushes the nose of object to the right or left to rotate (angular velocity)

L-o-S Chasing in CE No need to determine path like in TBE, movement updates are in floating-point (rounding to nearest pixel integer gives good approximation) Similarly, rotation angle (“looking at” direction) should be re-calculated every time player changes position

L-o-S Chasing in CE Curved path taken by predator when chasing prey What happens if the speed of the predator is set too fast?

Preventing overshooting Implement speed control logic to allow predator to slow down as it gets closer to prey Calculate distance between both, if distance < some predefined distance, reduce thrust velocity to slow down

L-o-S Evading Since we now understand L-o-S Chasing, L-o-S Evading is just doing everything the reverse TBE Update movement in opposite direction (good enough!) CE “Looking at” rotation should steer to opposite face Update movement in opposite direction

Further improvements? Acceleration (and deceleration) for thrust force and steering force? Any way to improve “intelligence” of chasing movement?

Intercepting Line-of-Sight Chase: NPC will always head directly towards player In the case of a moving target, what happens? Player Line-of-sight Chase NPC

Intercepting Movement can be more “intelligent”, if it knows how to intercept the player somewhere along the player’s “trajectory”. How do we work this out? What information do we need? Player Line-of-sight Chase NPC

Intercepting – In Principle Predict some “future” position of the player and move towards that position, so that it reaches the same time as player… Player Line-of-sight Chase A “future” position of player NPC Intercepting Chase

Intercepting – A “Future” Position “Future” can be safely predicted linearly How to compute this position? Player Line-of-sight Chase A “future” position of player NPC Intercepting Chase

Intercepting Important to consider relative velocities (direction and magnitude) and distance instead of just their current positions Let’s work out the math to determine what is the predicted future position…

Intercepting - Code Recall: You would have implemented the Enemy class already, and have it to chase the player. Target  Player position For Intercept, Target  Player’s predicted future position Easy to modify and adapt code from Chase to Intercept Function to be called through the game loop to constantly update interception point

Intercepting

Intercepting There are scenarios where intercepting may not be possible or unrealistic NPC moving at much slower velocity NPC ends up chasing from behind a player moving in straight line NPC gets ahead of player and moving at a faster speed

Pattern Movement Simple way of giving the illusion of intelligent behavior “Choreographed” movements of enemy NPCs making organized maneuvers, loops Can be used effectively for Enemy NPCs (patrol, attack) Friendly NPCs (to exhibit or act intelligently to cooperate with player) Secondary NPCs (doing all kinds of random patterned actions)

Standard Pattern Movement Uses lists or arrays of encoded instructions to tell NPC how and where to move each step Easy to loop through again Sample control data ControlData { double turnRight; double turnLeft; double stepForward; double stepBackward; };

Standard Pattern Movement Can include other kinds of actions: Fire weapon, release chaff, drop bomb, do nothing, speed up, slow down, etc. Pattern initialization Hardcoded in game Loaded from a data file (text, XML) Process pattern Maintain and increment an index to the pattern array through the game loop

Standard Pattern Movement void GameLoop(void) { . . . Object.orientation += Pattern[CurrentIndex].turnRight; Object.orientation -= Pattern[CurrentIndex].turnLeft; Object.x += Pattern[CurrentIndex].stepForward; Object.x -= Pattern[CurrentIndex].stepBackward; CurrentIndex++; . . . }

Pattern Movement in TBE Bresenham’s line drawing algorithm used again to pre-calculate path steps More complex paths can be created by joining up line segments Each new segment will begin once a previous one ends Line-of-sight function  End of segment now assigned as the target

Pattern Movement in TBE Instead of resetting L-o-S path array, new line segment is appended to previous path (Why do we do this?)

Pattern Movement in TBE High-level code for pattern initialization entityList[1].InitializePathArrays(); entityList[1].BuildPathSegment(10, 3, 18, 3); entityList[1].BuildPathSegment(18, 3, 18, 12); entityList[1].BuildPathSegment(18, 12, 10, 12); entityList[1].BuildPathSegment(10, 12, 10, 3); entityList[1].NormalizePattern(); entityList[1].patternRowOffset = 5; entityList[1].patternColOffset = 2;

Patrolling: Cyclical & Ping Pong B B C C D ABCBABCBA ABCDABCD

Pattern Movement in TBE Ping Pong Patrolling entityList[1].InitializePathArrays(); entityList[1].BuildPathSegment(10, 3, 18, 3); entityList[1].BuildPathSegment(18, 3, 10, 3); entityList[1].NormalizePattern(); entityList[1].patternRowOffset = 5; entityList[1].patternColOffset = 2;

Pattern Movement in TBE To prevent repetition and predictability  Add a random factor for choosing alternative patrolling path How to implement?

Pattern Movement in PSE PSE – Physically Simulated Environments (or Continuous Environments with Physics) You may specify positions for NPC to traverse, but that defeats the purpose of using CE. Bad realism! Control structure needs to be designed to accommodate forces (thrust, steering)

Pattern Movement in PSE struct ControlData { bool PThrusterActive; bool SThrusterActive; double dHeadingLimit; double dPositionLimit; bool LimitHeadingChange; bool LimitPositionChange; }; Changes in heading and position are relative in patrolling Based on this control data, how do you initialize a square pattern patrol?

Pattern Movement in PSE More implementation details can be found in textbook

Other Useful Movements Velocity Matching (for friendly NPCs, flocking) Wander (roaming NPCs) (can be found in Millington’s book)