240 likes | 364 Views
Artificial Intelligence in Game Design. Camera Control. The Camera as a NPC. Good camera placement vital to good gameplay! Must maintain clear view of selected character Must highlight significant events to the player
E N D
Artificial Intelligence in Game Design Camera Control
The Camera as a NPC • Good camera placement vital to good gameplay! • Must maintain clear view of selected character • Must highlight significant events to the player • Must anticipate player movements, providing clear view of where the player’s character is moving • Best approach: Treat like an intelligent character • Must move in logical ways to perform goals • Movement must be smooth, not “jerky” or discontinuous • Best actions often depend on state of game
Categories of Camera Perspective • First person: From perspective of player’s character • Implemented by parenting camera to “head” of character • Few AI-related problems, since camera totally controlled by player
Categories of Camera Perspective • Third person: From point of view of “user” observing world and its inhabitants • Often “birds eye” view showing world around character • Few AI-related problems, since camera usually fixed above player
Categories of Camera Perspective • “First and a half person” • From POV slightly behind and to side of player • Combines character POV with view of character
“First and a Half” Person • Usually implemented by parenting camera to position relative to player character • Maintains same relative position/angle to player as player moves
Problems • Must make sure no obstacles between camera and character • Will have to move camera around obstacles to keep character visible • Must make sure camera shot includes all relevant characters • Current opponent NPCs • Player themselves!
Camera Position Selection • Usually have many viable camera positions for first-and-a-half person perspective • Choose the “best” one based on current situation
Raycast Method • Project “rays” in different directions from character relative to camera angle (xangle, yangle) • (xangle + Θ, yangle) • (xangle - Θ, yangle) • (xangle, yangle + Θ) • (xangle, yangle - Θ)
Raycast Method • Use raycasting to see if any intersect an obstacle atdistance shorter than distance from camera to character • These are potential situationswhere camera may be blocked in future dependingon how character moves • Example: Vector B intersects obstacle
Raycast Method • Camera should flee vectors that are potential problems • Change relative angle • Potentially change distance/height • Should arrive at original angle once obstacle cleared
Multipoint Method • Generate points in region where camera is moving to • Evaluate suitability of each point • Move camera to most suitable point
Defining “Suitability” • Primarily based on constraints on relative position to character • Distance constraint: Penalty proportional to how far camera is from desired distance to character • Height constraint: Penalty proportional to how far camera is from desired height relative to character • Orientation constraint:Penalty proportional to how far camera is from desired angle relative to character
Defining “Suitability” • Collision detection and visibility constraints • 0 if all characters visible • 1 if main character not visible • Possibly defined as “more than half of torso/head occluded” • 0 <n≤ 1 based on degree to which other important characters in area of player not visible
Defining “Suitability” • Different components usually weighted Suitability = WDdistance constraint +WHheight constraint +WOorientation constraint +Wvvisibility constraint +(Wv usually larger than others) • Key idea: Developers can “tune” weights • Can experiment with different values by playing game • Which give most “intuitive” camera behavior?
Regional Constraints • May want to constrain camera to specific area in space • Example: Showing dialog between two characters should keep camera locked in torus around the characters • Points to search limited to those that fall within this region
Smoothing • Potential problem: Several nearby points might have similar suitability measures • Camera may oscillate back and forth between them as character moves • “Jerky camera” appearance
Smoothing • Apply smoothing (averaging) to suitability function • Suitability (x, y) = 0.5 * Suitability (x, y) + 0.125 * Suitability (x+1, y) + 0.125 * Suitability (x-1, y) + 0.125 * Suitability (x, y+1) + 0.125 * Suitability (x, y-1) + • Usually results in one point consistently best over period of time
State-based Suitability • Different constraint weights best in different game situations • Driving: Fixed angle relative to player most important • Jumping: Correct height most important to keep player from jumping out of camera • Multicharacter battle: Keeping all characters in frame
State-based Suitability • Can use finite state machine for camera to choose appropriate weights/constraints Area with pits Jumping constraints Walking constraints Car reached Driving constraints
Multicharacter Games • Some games allow player to swap control between several different characters • Camera must show world from perspective of current character • Transition should be smooth to avoid player confusion Don’t just jump
Multicharacter Games • Move camera to new character in smooth transition • May have to use steering behaviors • Arrive at position behind next player character • Flee obstacles, positions where character not visible
Multicharacter Games • Best approach may be to move over obstacles • Temporarily take “third person” approach
Camera Events • Camera must often respond to other game events • Example: Off-screen explosion should cause “camera shaking” • Camera must be part of game messaging system • List of current world events maintained • Camera must regularly poll list for relevant events, take appropriate action Game Engine