game physics and projectiles l.
Skip this Video
Loading SlideShow in 5 Seconds..
Game Physics and Projectiles PowerPoint Presentation
Download Presentation
Game Physics and Projectiles

Loading in 2 Seconds...

play fullscreen
1 / 13

Game Physics and Projectiles - PowerPoint PPT Presentation

  • Uploaded on

Game Physics and Projectiles Soon Tee Teoh CS 134 Interactive Systems and Events In a game, the player interacts with the game through input devices: mouse, keyboard, joystick, steering wheel etc. The OS manages user input A user input generates an Interrupt at the hardware level

I am the owner, or an agent authorized to act on behalf of the owner, of the copyrighted work described.
Download Presentation

PowerPoint Slideshow about 'Game Physics and Projectiles' - lotus

An Image/Link below is provided (as is) to download presentation

Download Policy: Content on the Website is provided to you AS IS for your information and personal use and may not be sold / licensed / shared on other websites without getting consent from its author.While downloading, if for some reason you are not able to download a presentation, the publisher may have deleted the file from their server.

- - - - - - - - - - - - - - - - - - - - - - - - - - E N D - - - - - - - - - - - - - - - - - - - - - - - - - -
Presentation Transcript
game physics and projectiles

Game Physics and Projectiles

Soon Tee Teoh

CS 134

interactive systems and events
Interactive Systems and Events
  • In a game, the player interacts with the game through input devices: mouse, keyboard, joystick, steering wheel etc.
  • The OS manages user input
    • A user input generates an Interrupt at the hardware level
    • Interrupt gets converted into event, and put in queue at the OS level
  • The application controls how to handle this event stream
game loop and events
Game Loop and Events
  • In a game, we need to run the game loop continuously.
  • At the same time, we need to receive input from the user, for example, the user has pressed a button, or moved the joystick.
  • How to handle this?
    • Several options:
      • Polling: Periodically query input devices to find out if event has occurred.
        • Non-blocking: If nothing has happened, then query function exits
      • Waiting: Wait until event happens
        • Blocking: Event query function will wait until event happens
    • The Callback abstraction
      • This uses the polling method
      • The program registers some functions to be called whenever an event occurs.
      • When event occurs, the registered callback function is called to handle the event.
      • Otherwise, if no event occurs, then the idle function is called to run the game loop.
    • Alternatively, game loop incorporates event handling

while (1) {





Game Loop

game loop and physics
Game Loop and Physics
  • The Game Loop is a function that is called continuously.
  • For example, it can be the following code (same as previous page):
  • Alternatively, put game loop in idle function, which is called whenever there is nothing else going on (callbacks handle events, so game loop does not):
  • Thus, a game loop may look like:
  • How to update the position of an object?
    • If we know its position and velocity/acceleration etc. and we know the time elapsed since the last game loop, we can update the object’s position.

while (1) GameLoop();

void idleFunc() { GameLoop(); }

Update position, velocity, acceleration etc. according to physics model. Also, perform collision detection.

Perform collision response if necessary.

t may be different each time

void GameLoop() {

float t = TimeSinceLastCall();

for (i=0;i<nCharacters;i++) Characters[i].AI();

for (i=0;i<nObjects;i++) Objects[i].UpdateStatus(t);


need t as argument

example object at constant velocity
Example: Object at Constant Velocity
  • Suppose in the previous game loop, an object is at position P.
  • Suppose that the object is traveling at constant velocity V.
  • Suppose that between the previous game loop and the current game loop, t amount of time has elapsed.
  • Then, the new position of the object is:

P + Vt

vector and its components
Vector and Its Components
  • A vector has a magnitude and direction.
    • Example: Force and velocity are vectors.
  • Often, the vector is in 2D or 3D space, so we express the vector as (x,y) or (x,y,z).
  • We also express a vector pictorially as an arrow.
  • Vector addition:
    • Just add the components
    • Pictorially, sum the arrows
  • Splitting vector to components:
    • For convenience, we often consider a vector in terms of orthogonal components.
    • For example, we split vector V into Va and Vb. So, V = Va + Vb

V = (2,1)

V1 + V2






  • At the starting point, an object is fired with a certain speed in a certain direction.
  • After that, there is no force acting on the object except gravity.
  • Given the initial position and velocity of the object, we wish to calculate its path. We also wish to calculate some other useful numbers.
projectile displacement over time
Projectile Displacement Over Time





Suppose that the projectile starts at (0,0).

Suppose that the initial velocity of the projectile is v0.

X is the horizontal direction, and Y is the vertical direction.

Then, the distance in the x and y direction over time t is:

x(t) = (v0 cos q) t

y(t) = (v0 sin q) t – (gt2)/2

Here, g is the gravitational acceleration.

projectile velocity over time
Projectile Velocity Over Time





We can also calculate the velocity over time:

Velocity in the x direction Vx(t) = v0 cos q

Velocity in the y direction Vy(t) = v0 sin q – gt

Overall velocity V(t) = sqrt(v02 – 2gtv0sin q + g2t2)

projectile maximum height
Projectile Maximum Height






We can also calculate the maximum height gained by the projectile:

Maximum height h = (v02 sin2q )/ (2g)

projectile time to impact
Projectile Time to Impact
  • To calculate time to impact, we consider three cases:
    • Case 1: Target is of the same height as projectile launch.
    • Case 2: Target is higher than projectile launch.
    • Case 3: Target is lower than projectile launch.
projectile time to impact12
Projectile Time to Impact

Case 1:

T = (2v0 sin q)/g

Case 2:

T = (v0 sin q)/g + sqrt(2(h-b)/g)



Case 3:

T = (v0 sin q)/g + sqrt(2(h+b)/g)



projectile total horizontal displacement
Projectile Total Horizontal Displacement

Total horizontal displacement R = v0 T cos q