Python simple bouncing physics -
i wondering if there's straightforward way implement bouncing physics in python, without modules physics. bouncing physics, don't mean gravity, mean more released ios game "okay?" philipp stollenmayer (https://appsto.re/us/1n7v5.i). know if ball hits straight edges, velocities inverted. so, given diagram: when ball hits , c, x velocities inverted, , when hits b , d, y velocities inverted. if our diagram looks this: given angle of platform, how can find new x , y velocities? also, how can convert these x , y velocities degrees?
what found out wikipedia bounce's line of symmetry perpendicular surface hits.
my final question how, in pygame, find angle of line, , create line angle.
p. s.: when answering question, please keel in mind math knowledge limited what's on nys algebra 1 regents in june :) don't go cauculus , trigonometry on me :)
reflectedvector = velocityvector - scale(surfacenormal, 2.0*dot(surfacenormal, velocityvector))
velocityvector
movement speed, represented vector, moving towards surface. surfacenormal
perpendicular surface, length of 1.
dot
dot product. dot(v1, v2) = v1.x*v2.x + v1.y*v2.y
scale
vector "scale" operation. scale(invec, scalar) = vector2d(invec.x*scalar, invec.y*scalar)
`
reflect velocity if directed towards surface, if moving away, don't.
- if
dot(surfacenormal, velocity) < 0
ball moving towards it. - if
dot(surfacenormal, velocity) == 0.0
ball in parallel surface. - if
dot(surfacenormal, velocity) > 0.0
ball moving away surface.
Comments
Post a Comment