Background Shapes & Collision Resolution (Top-down and Side-scrolling)

Slides:



Advertisements
Similar presentations
How to Make a Game Like Space Invaders. What IS Space Invaders? a SHMUP (shoot-em-up) Player has one ship, enemy has many Player and enemies interact.
Advertisements

Ray tracing. New Concepts The recursive ray tracing algorithm Generating eye rays Non Real-time rendering.
Intersection Testing Chapter 13 Tomas Akenine-Möller Department of Computer Engineering Chalmers University of Technology.
Collision Detection CSCE /60 What is Collision Detection?  Given two geometric objects, determine if they overlap.  Typically, at least one of.
Collision Detection and Resolution Zhi Yuan Course: Introduction to Game Development 11/28/
May 19, 2012 Lloyd Moore, President/Owner Just kidding – next slide please!
Intro to Game Development An introduction to Swing, Java2D, JOGL, and game design Created by: Dennis Lawter and Dustin Scott.
Video Game Math: Circle-on-Circle collision detection.
Windows 8 Windows Phone 8 Web Mobile … and WakeUpAndCode.com.
INTRODUCTION TO SCRATCH. About Me Resources Scratch Website Learn Scratch Washington-Lee Computer.
CS 4730 Collision Detection CS 4730 – Computer Game Design.
Created in 2011 at Liberty High School. Getting Started Overview on Magnet Tool – Graphics – Text – Image – Video – Sound – Wall A Sample Glog How to.
INTRODUCTION TO THE SCRATCH PROGRAMMING ENVIRONMENT.
SOURCE 2006 Presentation by Luke Arntson Game Programming Optimization.
Collision and Animation Systems in Games Jani Kajala Lead Programmer / Chief Technology Officer, Pixelgene Ltd (0)
Game Maker Day 2 Making a Maze Game.
Learning Game Maker Studio:
Art 315 Lecture 5 Dr. J. Parker AB 606. Last time … We wrote our first program. We used a tool called GameMaker. The program we wrote causes a ball to.
Week 13 - Friday.  What did we talk about last time?  Ray/sphere intersection  Ray/box intersection  Slabs method  Line segment/box overlap test.
Addison Wesley is an imprint of © 2010 Pearson Addison-Wesley. All rights reserved. Chapter 7 The Game Loop and Animation Starting Out with Games & Graphics.
Does this point lie on this line? The Point-Slope format (y – y 1 ) = m(x – x 1 )
CO1301: Games Concepts Dr Nick Mitchell (Room CM 226) Material originally prepared by Gareth Bellaby.
Sample Video Game & Sound. The Plan 1.Game Theme 2.Game Structure 3.Sprites 4.Trackers 5.Collisions 6.Score 7.Levels 8.Splash Screens 9.Design 10.Implementation.
CIS 350 – I Game Programming Instructor: Rolf Lakaemper.
Game Maker Terminology
Artificial Intelligence in Game Design Complex Steering Behaviors and Combining Behaviors.
CS 325 Introduction to Computer Graphics 03 / 22 / 2010 Instructor: Michael Eckmann.
L ECTURE 6 Announcements. Next week will be great! Three major things are happening next week: – Zynga guest lecture – Your game pitches (more details.
Final Project Proposal Space Invaders By Jordan Mahaffey.
Lesson 3: Arrays and Loops. Arrays Arrays are like collections of variables Picture mailboxes all lined up in a row, or storage holes in a shelf – You.
Let’s Bounce! or Physics of Collisions Part 1 Games Fundamentals © by Jarek Francik Kingston University, London
CRE Programming Club Class #9 Robert Eckstein and Robert Heard.
Lesson 2: Reading a program. Remember: from yesterday We learned about… Precise language is needed to program Actors and Classes Methods – step by step.
Real Life Quadratic Equations Maximization Problems Optimization Problems Module 10 Lesson 4:
Artificial Intelligence in Game Design Lecture 8: Complex Steering Behaviors and Combining Behaviors.
Tank Game Part 3 of 6. Secondary Weapons and Pick ups Pick ups will appear randomly in the battle area and can be collected by driving into them. Each.
Construct 2 Game Development for Kids Platformer Tutorial: Part 1 Shahed Chowdhuri.
GAME:IT Paddle Ball Objectives: Review skills from Introduction Create a background Add simple object control (up and down) Add how to create a simple.
Game Maker Tutorials Introduction Clickball IntroductionClickball Where is it? Shooting Where is it?Shooting.
2D Graphics Optimizations
Sound and more Animations
MORE Genre Specific Physics
Intro CS – Screens and Variables
Game Maker Intro to Programming Game Maker Pop Quiz (Both Groups)
Game Engine Architecture
CS 134 More Graphics.
© Craig Zilles (adapted from slides by Howard Huang)
Intro & Point-to-Box, Circle-to-Circle, Point-to-Circle
Collision Detection Box-to-Box.
Sentinel logic, flags, break Taken from notes by Dr. Neil Moore
Sentinel logic, flags, break Taken from notes by Dr. Neil Moore
Quadtrees 1.
Tutorial on using Java Sprite Animation
Lesson 3.2 Review: Identifying concepts
A Powerpoint about ...and irony
Collision Detection Platforms.
Week 6: Time and triggers!
How to find the intersection of two lines graphically using the TI-83
CS679 - Fall Copyright Univ. of Wisconsin
Game Maker Intro to Programming Game Maker Pop Quiz (Both Groups)
Collision Detection.
AS-Level Maths: Core 2 for Edexcel
CO Games Concepts Week 12 Collision Detection
Game Programming Algorithms and Techniques
Nate Brunelle Today: Games
Game Programming Algorithms and Techniques
Energy Problems.
Presentation transcript:

Background Shapes & Collision Resolution (Top-down and Side-scrolling) CS 134 Background Shapes & Collision Resolution (Top-down and Side-scrolling)

Today in Video Games

Physics Update Overview So far: Collision Detection (sprite / sprite) To cover: Collision Detection (sprite / background) Collision Resolution Advanced Actor Motion

Backgrounds Recall how we stored the tile positions in an array? int[] bg; Collision can go there too!

Backgrounds class Tile { int image; boolean coll; }; Tile[] bg; Other information can go in a tile as well!

Backgrounds As the player moves, you will need to collide against all the background shapes. AABB / AABB Use the camera drawing optimization Start: pX / tileW End: (pX + pW) / tileW Similar in Y

Questions? (Remember, this is just for DETECTING collisions) Backgrounds Questions? (Remember, this is just for DETECTING collisions)

Collision Resolution The job of collision resolution is to “fix” the simulation state so that it is accurate again.

Collision Resolution For now, assume a simple top down game Up / Down / Left / Right move player Background is “block shaped”

Collision Resolution Simplest possible collision resolution is with bullets Deal damage to player Remove bullet Check if player is dead

Collision Resolution For colliding with walls Simple solution: Back up player to prev position More complex: Back up player to when the collision starts This may be enough for some games!

Collision Resolution Best feeling solution: Back up on each axis Back up on X axis by overlap with wall tile Back up on Y axis by overlap with ceiling tile This allows smooth sliding along walls Also, can do things like wall jumps, pushing, etc. by remembering which axes you collided with prev frame More state for a player!

Collision Resolution How do you know the overlap? Collision is just returning true / false! right1 < left2 is false, return right1 – left2 Similar for other sides

Collision Resolution Questions?

Actor Motion Basic actor motion isn't enough for many games In maze games, the player should be given some give to going around corners In platformers, the player should be affected by gravity One way walls are a common thing too

Actor Motion Maze edge motion: When moving, if you are just barely colliding, fix the motion to a tile boundary Here, pressing up will still get Link into the fortune teller's house

Actor Motion Add new state, set during motion to detect near misses When you release pressing the direction, clear the near miss state. If in a near miss state, move in the near miss direction instead

Actor Motion Frame 1: Link would collides with statue, set near miss left, moves right Frame 2: Still in near miss state, move right Frame 3: No longer in near miss state, move up

Actor Motion

Raycasting Recall: Physics is running at a fixed rate Collision is only checked AFTER objects move Problem: Fast moving objects can jump past an object Raycasts shoot an infinitely long ray to collide with AABB / Circles

WARNING! WARNING! INCOMING MATH Raycasting WARNING! WARNING! INCOMING MATH

Ray / Circle Ray formula: Circle formula: 𝑝=𝐀+𝑡𝐁 𝑡≥0 𝑟=∣𝑝−𝐎∣ 𝑟= 𝑝−𝐎 ⋅ 𝑝−𝐎

Ray / Circle Plug ray into circle formula and simplify:

Ray / Circle Three possibilities (solutions for t): t has no solutions Ray does not intersect the circle t has one negative, one positive solution Ray starts inside the circle, collides at positive solution t has two positive solutions Ray hits circle, use the lesser solution

Ray / Circle Optimization Remember, we don't care if ray starts inside of circle! Calculate t via: Collision is only when t is positive. 𝑡= −𝑏− 𝑏 2 −4𝑎𝑐 2a

Ray / AABB Intersect ray with all sides, choose earliest intersection that is inside box Four sides of of AABB are: x = left x = right y = left y = right

Ray / AABB Plug into side formula and simplify: A_x + t B_x = left → t = (left – A_x) / B_x A_x + t B_x = right → t = (right – A_x) / B_x Solve for t Given t, check if specified point is in box edge Top < A_y + t B_y < bottom Then do same thing for y, and choose earliest t

Ray / AABB Optimization For any particular direction, only two sides could be the earliest Unless the ray is exactly parallel to X or Y, only the later of the two times can be inside the box

Homework 3 Some sort of projectile with “enemies” to hit. When the projectile hits the enemy, the projectile goes away. Enemies can have health, so they need to be hit multiple times. Extra credit: Enemies can shoot projectiles too! Raycast-style instant shots