Game Physics Test

63
GameSalad Physics Young-min Kang Tongmyong University

description

Implemetation of an App testing GameSalad Physics

Transcript of Game Physics Test

Page 1: Game Physics Test

GameSalad PhysicsYoung-min Kang

Tongmyong University

Page 2: Game Physics Test

goal• Physics Test Application

Page 3: Game Physics Test

scene1 - gravity• prepare some images

and actors

Page 4: Game Physics Test

add some behaviors

Page 5: Game Physics Test

create a ball actor

If it’s out of window, destroy it

Page 6: Game Physics Test

add gravity and spawn balls

gravity

Behavior of the instance

Page 7: Game Physics Test

Be careful• These are not ‘moveable’

only moveable

Page 8: Game Physics Test

Test it• When you touch the background, balls will appear and fall

Page 9: Game Physics Test

scene 2 - collision• prepare more actors • place them in the scene

Page 10: Game Physics Test

ball collision• add more

behaviors to the ball actor

Page 11: Game Physics Test

You will see colliding balls

Page 12: Game Physics Test

scene 3 - bounciness• add new actors of which bounciness will be changed

moveable

not moveable

will collide with our new floor actor

these guys will display their own bounciness

Page 13: Game Physics Test

touch input for bounciness• prepare this image

bouncinesses of the ball and the floor will be determined by where you touch inside this actor !x direction: floor direction y direction: ball direction

new attributes

Page 14: Game Physics Test

table for bouncinesses• Prepare a table “TB Bounciness”

Page 15: Game Physics Test

place them in the scene

actors for some message display

Page 16: Game Physics Test

bounciness input

Spawn balls whenever this actor is touched

Page 17: Game Physics Test

change bounciness• add more behaviors

Page 18: Game Physics Test

Test• balls bounce with different bounciness values

Page 19: Game Physics Test

scene 4 - elasticity• Prepare a scene which look like this

final result

Page 20: Game Physics Test

add properties• force and other variable for calculating the force

Page 21: Game Physics Test

set values for each instancemoveable

not moveable not moveable

Page 22: Game Physics Test

index setting• behavior for circle_icon

1 2 3 4 5 6 7 8 9 10

Page 23: Game Physics Test

prepare a table• table for storing the locations of circles

Page 24: Game Physics Test

behavior of moveable circles

Page 25: Game Physics Test

Compute Differenceindex-1

index+1index

(dx1,dy1)

(dx2,dy2)

Page 26: Game Physics Test

compute distancesindex-1

index+1

index

l1

l2

Page 27: Game Physics Test

normalize the directions

Page 28: Game Physics Test

compute spring forcef =

nX

i=1

k(li � l0i )~di

k = 10

l0i = 5

Page 29: Game Physics Test

update velocityvt+h = vt +

Z t+h

tadt

m = 1 ) f = a vt+h = vt +

Z t+h

tfdt

Euler integration

vt+h = vt + hfh=0.03

Page 30: Game Physics Test

Test it

Page 31: Game Physics Test

scene 5 - friction• prepare a scene

Page 32: Game Physics Test

different friction values• 30, 20, 10, 0 for floors which are not moveable

• 0 for the left box on each floor

• 3, 2, 1, 0 for the right boxes

Page 33: Game Physics Test

scene 6 - attraction• prepare a scene like this

final result

Page 34: Game Physics Test

we need more attributes• add an attribute to the background actor

• count:integer

• add two attributes to the game (global variables)

• touchX:real

• touchY:real

Page 35: Game Physics Test

behaviors of background• spawn planets that will be attracted by sun

Page 36: Game Physics Test

behaviors of background• prepare a sun actor and spawn it

• when the background it touched

• store the touch location to game.touchX and game.touchY

Page 37: Game Physics Test

“sun” actor• prepare a “sun” actor and constrain its location to

the touched point

Page 38: Game Physics Test

“planets” and its behaviors• we need some attributes for this actor

• these planets will be attracted by “sun”

• planet behavior

• compute attraction force and update its velocity

• “every 0.03 seconds (=h), update the state of the planet”

Page 39: Game Physics Test

vector from planet to sun• d = (dx, dy)

• sun is located at (Game.touchX, Game.touchY)

Page 40: Game Physics Test

compute distance between planet and sun

• simple computation

Page 41: Game Physics Test

normalize the direction• also simple

Page 42: Game Physics Test

compute “attraction”• attraction force

fattr = Cattrmplanet ·msun

l2d

Cattr ·mplanet ·msun = 2, 000, 000

Page 43: Game Physics Test

collision handling

Page 44: Game Physics Test

test

Page 45: Game Physics Test

scene 7- drag• prepare a scene like this

Page 46: Game Physics Test

set different drag values

Page 47: Game Physics Test

test

Page 48: Game Physics Test

scene 8 - rope physics

• rope is not elastic

• joint is required to express rope

• no joints are available in GameSalad

• we will use “fake” dynamics

Page 49: Game Physics Test

model

• rope model

• linked “line segments”

• line segments are linked with rivets

• we will display only the rivets

Page 50: Game Physics Test

table for locations of rivets

• 16 rivets

• location (x,y)

• index

Page 51: Game Physics Test

behaviors of background• spawn 16 rivets and locate them in accordance with the table contents

• assign indices to the rivets Explained in the next slide

Page 52: Game Physics Test

assigning unique index to each rivet

• add an attribute to Game

• Shared Integer Variable: integer

• every time you spawn a rivet, you set this value and the spawned rivet will use this for its own index

Page 53: Game Physics Test

behaviors of background• if touched, adjust Game.touchX and Game.touchY

Page 54: Game Physics Test

How rivets move• when it is spawned

• set its unique index

• rivet with index 1

• immediately moves to the touched position

• other rivets

• each rivet tries to keep the given distance to the previous rivet of which index is 1 less than its own

Page 55: Game Physics Test

rivet with index 1constrain its location to the touched position

store its location to the table

Page 56: Game Physics Test

other rivets• update its location every 0.03 seconds

store its location to the table

state update

Page 57: Game Physics Test

apply gravity• we apply our own gravity instead of GameSalad gravity

Page 58: Game Physics Test

compute difference• difference with the previous rivet

Page 59: Game Physics Test

distance to the previous one• simple…

Page 60: Game Physics Test

normalize the direction• simple…

Page 61: Game Physics Test

adjust location and velocity• try to keep the given distance

Padjusted = P+ (l � l0)~d

• change of position

• velocity that incur the change should be computed

!

• original velocity: v

vadjusted = 0.5 · v + 0.5 · v+

Our model

v+

v+ =(l � l0)~d

h

Page 62: Game Physics Test

adjust location and velocity• try to keep the given distance

Page 63: Game Physics Test

test