game physics test
DESCRIPTION
Implemetation of an App testing GameSalad PhysicsTRANSCRIPT
![Page 1: Game Physics Test](https://reader034.vdocument.in/reader034/viewer/2022042521/558c8eb3d8b42a15338b45a4/html5/thumbnails/1.jpg)
GameSalad PhysicsYoung-min Kang
Tongmyong University
![Page 2: Game Physics Test](https://reader034.vdocument.in/reader034/viewer/2022042521/558c8eb3d8b42a15338b45a4/html5/thumbnails/2.jpg)
goal• Physics Test Application
![Page 3: Game Physics Test](https://reader034.vdocument.in/reader034/viewer/2022042521/558c8eb3d8b42a15338b45a4/html5/thumbnails/3.jpg)
scene1 - gravity• prepare some images
and actors
![Page 4: Game Physics Test](https://reader034.vdocument.in/reader034/viewer/2022042521/558c8eb3d8b42a15338b45a4/html5/thumbnails/4.jpg)
add some behaviors
![Page 5: Game Physics Test](https://reader034.vdocument.in/reader034/viewer/2022042521/558c8eb3d8b42a15338b45a4/html5/thumbnails/5.jpg)
create a ball actor
If it’s out of window, destroy it
![Page 6: Game Physics Test](https://reader034.vdocument.in/reader034/viewer/2022042521/558c8eb3d8b42a15338b45a4/html5/thumbnails/6.jpg)
add gravity and spawn balls
gravity
Behavior of the instance
![Page 7: Game Physics Test](https://reader034.vdocument.in/reader034/viewer/2022042521/558c8eb3d8b42a15338b45a4/html5/thumbnails/7.jpg)
Be careful• These are not ‘moveable’
only moveable
![Page 8: Game Physics Test](https://reader034.vdocument.in/reader034/viewer/2022042521/558c8eb3d8b42a15338b45a4/html5/thumbnails/8.jpg)
Test it• When you touch the background, balls will appear and fall
![Page 9: Game Physics Test](https://reader034.vdocument.in/reader034/viewer/2022042521/558c8eb3d8b42a15338b45a4/html5/thumbnails/9.jpg)
scene 2 - collision• prepare more actors • place them in the scene
![Page 10: Game Physics Test](https://reader034.vdocument.in/reader034/viewer/2022042521/558c8eb3d8b42a15338b45a4/html5/thumbnails/10.jpg)
ball collision• add more
behaviors to the ball actor
![Page 11: Game Physics Test](https://reader034.vdocument.in/reader034/viewer/2022042521/558c8eb3d8b42a15338b45a4/html5/thumbnails/11.jpg)
You will see colliding balls
![Page 12: Game Physics Test](https://reader034.vdocument.in/reader034/viewer/2022042521/558c8eb3d8b42a15338b45a4/html5/thumbnails/12.jpg)
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](https://reader034.vdocument.in/reader034/viewer/2022042521/558c8eb3d8b42a15338b45a4/html5/thumbnails/13.jpg)
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](https://reader034.vdocument.in/reader034/viewer/2022042521/558c8eb3d8b42a15338b45a4/html5/thumbnails/14.jpg)
table for bouncinesses• Prepare a table “TB Bounciness”
![Page 15: Game Physics Test](https://reader034.vdocument.in/reader034/viewer/2022042521/558c8eb3d8b42a15338b45a4/html5/thumbnails/15.jpg)
place them in the scene
actors for some message display
![Page 16: Game Physics Test](https://reader034.vdocument.in/reader034/viewer/2022042521/558c8eb3d8b42a15338b45a4/html5/thumbnails/16.jpg)
bounciness input
Spawn balls whenever this actor is touched
![Page 17: Game Physics Test](https://reader034.vdocument.in/reader034/viewer/2022042521/558c8eb3d8b42a15338b45a4/html5/thumbnails/17.jpg)
change bounciness• add more behaviors
![Page 18: Game Physics Test](https://reader034.vdocument.in/reader034/viewer/2022042521/558c8eb3d8b42a15338b45a4/html5/thumbnails/18.jpg)
Test• balls bounce with different bounciness values
![Page 19: Game Physics Test](https://reader034.vdocument.in/reader034/viewer/2022042521/558c8eb3d8b42a15338b45a4/html5/thumbnails/19.jpg)
scene 4 - elasticity• Prepare a scene which look like this
final result
![Page 20: Game Physics Test](https://reader034.vdocument.in/reader034/viewer/2022042521/558c8eb3d8b42a15338b45a4/html5/thumbnails/20.jpg)
add properties• force and other variable for calculating the force
![Page 21: Game Physics Test](https://reader034.vdocument.in/reader034/viewer/2022042521/558c8eb3d8b42a15338b45a4/html5/thumbnails/21.jpg)
set values for each instancemoveable
not moveable not moveable
![Page 22: Game Physics Test](https://reader034.vdocument.in/reader034/viewer/2022042521/558c8eb3d8b42a15338b45a4/html5/thumbnails/22.jpg)
index setting• behavior for circle_icon
1 2 3 4 5 6 7 8 9 10
![Page 23: Game Physics Test](https://reader034.vdocument.in/reader034/viewer/2022042521/558c8eb3d8b42a15338b45a4/html5/thumbnails/23.jpg)
prepare a table• table for storing the locations of circles
![Page 24: Game Physics Test](https://reader034.vdocument.in/reader034/viewer/2022042521/558c8eb3d8b42a15338b45a4/html5/thumbnails/24.jpg)
behavior of moveable circles
![Page 25: Game Physics Test](https://reader034.vdocument.in/reader034/viewer/2022042521/558c8eb3d8b42a15338b45a4/html5/thumbnails/25.jpg)
Compute Differenceindex-1
index+1index
(dx1,dy1)
(dx2,dy2)
![Page 26: Game Physics Test](https://reader034.vdocument.in/reader034/viewer/2022042521/558c8eb3d8b42a15338b45a4/html5/thumbnails/26.jpg)
compute distancesindex-1
index+1
index
l1
l2
![Page 27: Game Physics Test](https://reader034.vdocument.in/reader034/viewer/2022042521/558c8eb3d8b42a15338b45a4/html5/thumbnails/27.jpg)
normalize the directions
![Page 28: Game Physics Test](https://reader034.vdocument.in/reader034/viewer/2022042521/558c8eb3d8b42a15338b45a4/html5/thumbnails/28.jpg)
compute spring forcef =
nX
i=1
k(li � l0i )~di
k = 10
l0i = 5
![Page 29: Game Physics Test](https://reader034.vdocument.in/reader034/viewer/2022042521/558c8eb3d8b42a15338b45a4/html5/thumbnails/29.jpg)
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](https://reader034.vdocument.in/reader034/viewer/2022042521/558c8eb3d8b42a15338b45a4/html5/thumbnails/30.jpg)
Test it
![Page 31: Game Physics Test](https://reader034.vdocument.in/reader034/viewer/2022042521/558c8eb3d8b42a15338b45a4/html5/thumbnails/31.jpg)
scene 5 - friction• prepare a scene
![Page 32: Game Physics Test](https://reader034.vdocument.in/reader034/viewer/2022042521/558c8eb3d8b42a15338b45a4/html5/thumbnails/32.jpg)
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](https://reader034.vdocument.in/reader034/viewer/2022042521/558c8eb3d8b42a15338b45a4/html5/thumbnails/33.jpg)
scene 6 - attraction• prepare a scene like this
final result
![Page 34: Game Physics Test](https://reader034.vdocument.in/reader034/viewer/2022042521/558c8eb3d8b42a15338b45a4/html5/thumbnails/34.jpg)
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](https://reader034.vdocument.in/reader034/viewer/2022042521/558c8eb3d8b42a15338b45a4/html5/thumbnails/35.jpg)
behaviors of background• spawn planets that will be attracted by sun
![Page 36: Game Physics Test](https://reader034.vdocument.in/reader034/viewer/2022042521/558c8eb3d8b42a15338b45a4/html5/thumbnails/36.jpg)
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](https://reader034.vdocument.in/reader034/viewer/2022042521/558c8eb3d8b42a15338b45a4/html5/thumbnails/37.jpg)
“sun” actor• prepare a “sun” actor and constrain its location to
the touched point
![Page 38: Game Physics Test](https://reader034.vdocument.in/reader034/viewer/2022042521/558c8eb3d8b42a15338b45a4/html5/thumbnails/38.jpg)
“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](https://reader034.vdocument.in/reader034/viewer/2022042521/558c8eb3d8b42a15338b45a4/html5/thumbnails/39.jpg)
vector from planet to sun• d = (dx, dy)
• sun is located at (Game.touchX, Game.touchY)
![Page 40: Game Physics Test](https://reader034.vdocument.in/reader034/viewer/2022042521/558c8eb3d8b42a15338b45a4/html5/thumbnails/40.jpg)
compute distance between planet and sun
• simple computation
![Page 41: Game Physics Test](https://reader034.vdocument.in/reader034/viewer/2022042521/558c8eb3d8b42a15338b45a4/html5/thumbnails/41.jpg)
normalize the direction• also simple
![Page 42: Game Physics Test](https://reader034.vdocument.in/reader034/viewer/2022042521/558c8eb3d8b42a15338b45a4/html5/thumbnails/42.jpg)
compute “attraction”• attraction force
fattr = Cattrmplanet ·msun
l2d
Cattr ·mplanet ·msun = 2, 000, 000
![Page 43: Game Physics Test](https://reader034.vdocument.in/reader034/viewer/2022042521/558c8eb3d8b42a15338b45a4/html5/thumbnails/43.jpg)
collision handling
![Page 44: Game Physics Test](https://reader034.vdocument.in/reader034/viewer/2022042521/558c8eb3d8b42a15338b45a4/html5/thumbnails/44.jpg)
test
![Page 45: Game Physics Test](https://reader034.vdocument.in/reader034/viewer/2022042521/558c8eb3d8b42a15338b45a4/html5/thumbnails/45.jpg)
scene 7- drag• prepare a scene like this
![Page 46: Game Physics Test](https://reader034.vdocument.in/reader034/viewer/2022042521/558c8eb3d8b42a15338b45a4/html5/thumbnails/46.jpg)
set different drag values
![Page 47: Game Physics Test](https://reader034.vdocument.in/reader034/viewer/2022042521/558c8eb3d8b42a15338b45a4/html5/thumbnails/47.jpg)
test
![Page 48: Game Physics Test](https://reader034.vdocument.in/reader034/viewer/2022042521/558c8eb3d8b42a15338b45a4/html5/thumbnails/48.jpg)
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](https://reader034.vdocument.in/reader034/viewer/2022042521/558c8eb3d8b42a15338b45a4/html5/thumbnails/49.jpg)
model
• rope model
• linked “line segments”
• line segments are linked with rivets
• we will display only the rivets
![Page 50: Game Physics Test](https://reader034.vdocument.in/reader034/viewer/2022042521/558c8eb3d8b42a15338b45a4/html5/thumbnails/50.jpg)
table for locations of rivets
• 16 rivets
• location (x,y)
• index
![Page 51: Game Physics Test](https://reader034.vdocument.in/reader034/viewer/2022042521/558c8eb3d8b42a15338b45a4/html5/thumbnails/51.jpg)
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](https://reader034.vdocument.in/reader034/viewer/2022042521/558c8eb3d8b42a15338b45a4/html5/thumbnails/52.jpg)
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](https://reader034.vdocument.in/reader034/viewer/2022042521/558c8eb3d8b42a15338b45a4/html5/thumbnails/53.jpg)
behaviors of background• if touched, adjust Game.touchX and Game.touchY
![Page 54: Game Physics Test](https://reader034.vdocument.in/reader034/viewer/2022042521/558c8eb3d8b42a15338b45a4/html5/thumbnails/54.jpg)
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](https://reader034.vdocument.in/reader034/viewer/2022042521/558c8eb3d8b42a15338b45a4/html5/thumbnails/55.jpg)
rivet with index 1constrain its location to the touched position
store its location to the table
![Page 56: Game Physics Test](https://reader034.vdocument.in/reader034/viewer/2022042521/558c8eb3d8b42a15338b45a4/html5/thumbnails/56.jpg)
other rivets• update its location every 0.03 seconds
store its location to the table
state update
![Page 57: Game Physics Test](https://reader034.vdocument.in/reader034/viewer/2022042521/558c8eb3d8b42a15338b45a4/html5/thumbnails/57.jpg)
apply gravity• we apply our own gravity instead of GameSalad gravity
![Page 58: Game Physics Test](https://reader034.vdocument.in/reader034/viewer/2022042521/558c8eb3d8b42a15338b45a4/html5/thumbnails/58.jpg)
compute difference• difference with the previous rivet
![Page 59: Game Physics Test](https://reader034.vdocument.in/reader034/viewer/2022042521/558c8eb3d8b42a15338b45a4/html5/thumbnails/59.jpg)
distance to the previous one• simple…
![Page 60: Game Physics Test](https://reader034.vdocument.in/reader034/viewer/2022042521/558c8eb3d8b42a15338b45a4/html5/thumbnails/60.jpg)
normalize the direction• simple…
![Page 61: Game Physics Test](https://reader034.vdocument.in/reader034/viewer/2022042521/558c8eb3d8b42a15338b45a4/html5/thumbnails/61.jpg)
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](https://reader034.vdocument.in/reader034/viewer/2022042521/558c8eb3d8b42a15338b45a4/html5/thumbnails/62.jpg)
adjust location and velocity• try to keep the given distance
![Page 63: Game Physics Test](https://reader034.vdocument.in/reader034/viewer/2022042521/558c8eb3d8b42a15338b45a4/html5/thumbnails/63.jpg)
test