Collision Detection Platforms.

Slides:



Advertisements
Similar presentations
Cosc 5/4730 Game Design. A short game design primer. A game or animation is built on an animation loop. – Instance variables of “objects” are updated.
Advertisements

1 Flash Actionscript Animation. 2 Introduction to Sprites We will now look at implementing Sprites in Flash. We should know enough after this to create.
Introduction What is this ? What is this ? This project is a part of a scientific research in machine learning, whose objective is to develop a system,
4.7 Quadratic Equations and Problem Solving BobsMathClass.Com Copyright © 2010 All Rights Reserved. 1 General Strategy for Problem Solving Understand the.
Introduction to TouchDevelop
Projectile Motion Review.
Advanced Phys. Ed. Tennis Notes General Info. Tennis can be played with wither two or four players. Points are scored by serving and placing the ball.
GAME:IT Junior Learning Game Maker: The Move Tab.
Learning Game Maker Studio:
Work, Energy, and Momentum Tanya Liu. Notes All my slides will be uploaded to Professor Dodero’s site:
11 Adding Tomato Targets Session Session Overview  We now have a game which lets a player bounce a piece of cheese on a bread bat  Now we have.
Programming Video Games
Game Maker Terminology
Zero Product Property. Zero Product Property If ab = 0, then ??? If ab = 0 then either a = 0 or b = 0 (or both). If the product 0f two numbers is 0, then.
Fall Semester Review: Physics Situation 1: Air resistance is ignored. A person is standing on a bridge that is 150 m above a river. a. If a stone with.
Introduction to Particle Simulations Daniel Playne.
Physics 218 Lecture 15: Momentum Alexei Safonov.
Physics 11 Advanced Mr. Jean May 8th, The plan: Video clip of the day Review of yesterday Perfectly Elastic Bouncing Balls Not perfectly Elastic.
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.
11 Adding a Bread Bat Session Session Overview  We have created a cheese sprite that bounces around the display  We now need to create a bread.
Introduction to Game Programming & Design III Lecture III.
AD 206 Intermediate CG : School of Art and Design : University of Illinois at Chicago : Spring 2009 Intro to Action Script 11 "The games of a people reveal.
Game Maker Tutorials Introduction Clickball IntroductionClickball Where is it? Shooting Where is it?Shooting.
Momentum And Energy Review BRYCE TOWLE EDCI 270 Click this Home Button to return to the main menu at anytime. Use this to switch from momentum to energy,
Linear Equations in Two Variables (Day 1) 1.3
Sound and more Animations
MORE Genre Specific Physics
Physics 11 Mr. Jean May 14th, 2012.
Graphical Output Basic Images.
Animation Frame Animation.
MOM! Phineas and Ferb are … Aims:
Physics Support Materials Higher Mechanics and Properties of Matter
Background Shapes & Collision Resolution (Top-down and Side-scrolling)
Balanced & Unbalanced Forces
Copyright © Cengage Learning. All rights reserved.
Intro & Point-to-Box, Circle-to-Circle, Point-to-Circle
3-7 Projectile Motion A projectile is an object moving in two dimensions under the influence of Earth's gravity; its path is a parabola. Figure Caption:
Collision Detection Box-to-Box.
Angles And Distances.
Making a simple platformer with physics
Linear Momentum and Second Newton’s Law
Example: Card Game Create a class called “Card”
CHESS.
Work Done by a Constant Force
Stop Animation Task.
PERSPECTIVES & ELEVATIONS
Oregon State University PH 211, Class #6
Work, Energy, and Power AP Physics C.
Image Formed by a Flat Mirror
Platformer Java Guide by Mr. Monroe.
Projectile Motion.
Isometric and Oblique Pictorials
Impulse-Momentum.
System: ball Surroundings: Earth Let distance fallen = h.
Tutorial on using Java Sprite Animation
Unit 1 Quiz #2 Forces & Interactions
Work AP Physics C.
Compressed springs store energy.
Basic Differentiation Rules and Rates of Change
Auxiliary Introduction
Work, Energy, and Power AP Physics C.
Plan The next question would be ... but how do we get the drawings from the 3D object? This will be explained over the next few pages. Take a look at.
PES 1000 – Physics in Everyday Life
Work, Energy, and Power AP Physics C.
Chapter 10 Algorithms.
Energy Problems.
Further Mechanics 1 : Elastic Collisions in Two Dimensions
Let’s play a game….
2019 SAIMC Puzzle Challenge General Regulations
Animation Translation.
Presentation transcript:

Collision Detection Platforms

Introduction When it comes to 2D games, one of the most common game mechanics is the ability to jump on and interact with platforms. For example, in Super Mario Bros. 1, you could: Jump on top of them Break some from underneath (as well as kill/stun the enemies directly overhead) You could bounce off the sides Some platforms moved with the player on top, etc. So, what’s the big deal, can’t we just use Box-to-Box collision? Yes…and no.

What’s the Problem? The problem with testing the bounding box is simply that it is not accurate enough. You need to know what part of the player is hitting the platform. One box cannot do that. The solution: Use 2 stage collision detection

The Idea… Imagine Mario in his bounding box, as shown below We need to break him up based on how he may potentially interact with the platforms Feet (land on top of platform) Head (Hit platform from below) Right side (bounce off a platform, or zero horizontal positive speed) Left side (bounce off a platform, or zero horizontal negative speed)

The Strategy We know that we will be doing this collision test a lot We want to reduce the work as much as possible, which is why we use the 2-stage process. The four sub rectangles are ONLY tested for collision if there is a collision with the bounding box We can set up the rectangles at two points: We set them up when the image is loaded, but we will need to maintain their locations by moving them whenever we move the player We set them up at the beginning of each round of tests (the beginning of an Update). This requires no maintenance, but does require calculations and variable declaration every update. The option you choose is up to you.

The Strategy The size and location of each sub rectangle require thought as well as trial and error. In the image below you can see that the head and feet boxes are not the entire width, this is to allow for angled falls and jumps that seem more realistic as oppose to having a toe stop a fall. You can play with the numbers to find what works for you, but the rectangles must be relative to the (x,y) of the bounding box as well as its width and height. (x,y) width height

0.2*w 0.6 * w Rectangle Setup 0.25 * h For my example, the head is 60% of the image width and 25% of its height. This implies its (x,y) is (img.x + (0.2 * img.width), img.y). Its width is 0.6 * img.width, height is 0.25 * img.height Feet were similar with a width of 70% and height of 25%. This implies the left and right rectangles have both a width and height of 50% of the image dimensions Left (x,y): (img.x, img.y + (0.25 * img.height)) Right (x,y): (img.x + (0.5 * img.width), img.y + (0.25 * img.height)) Left and Right Width is 0.5 * img.width, height is 0.5 * img.height Feet (x,y): (img.x + (0.15 * img.width), img.y + (0.75 * img.height)) Feet Width is 0.7 * img.width, height is 0.25 * img.height Now, all of these calculations are either done once when the image is loaded, followed by updates every frame OR, they are done at the beginning of each player collision detection process 0.25 * h 0.15*w 0.7 * w

The Process The detection process is the same as we have previously discussed. Here is a rough logic outline: set collision to false // assume there will be no collision For each collidable platform in the game if the current platform collides with the player’s bounding box if the current platform collides with feet adjust player y value to platform.y – player.height (sets them perfectly on top) zero any vertical velocity set collision to true else if the current platform collides with head adjust player y value to platform.y + platform.height (sets player perfectly below platform) multiply vertical velocity by -1 to reverse direction else if the current platform collides with left adjust player x value to platform.x + player.width (sets player perfectly left of platform) multiply horizontal velocity by -1 to reverse direction else if the current platform collides with right adjust player x value to platform.x + platform.width (sets player perfectly right of platform) multiply horizonal velocity by -1 to reverse direction end if End for return collision