Vector sliding/bouncing

BlitzMax Forums/BlitzMax Programming/Vector sliding/bouncing

Jake L.(Posted 2008) [#1]
Hi there,

I have the following code to bounce an object:
'Vx/y= Velocity (incoming object)
'normalx/y = surface-normal
'linex/y   = line vector

dotprod=Vx*normalx+Vy*normaly
resx=-2*dotprod*normalx + Vx
resy=-2*dotprod*normaly + Vy
Vx= resx * (1-Damping)
Vy= resy * (1-Damping)


While bouncing works well, I'm stucked getting sliding working. How do I need to fit the line vector into this to get the sliding velocity? Best of all would be to have a modifier bounce# to define the amount of bounce/slide (e.g. bounce=0 means full sliding, bounce=0.5 means the angle halfway between full bounce and slide).

I'm aware of the existing threads about this topic, but I can't produce a working solution out of them, so maybe someone can push me in the right direction.

Thanks
Jake


Dreamora(Posted 2008) [#2]
to implement sliding, you have to make the "sliding percentage" affect the "reflection" vector, in your equation this means -2*dotprod*normalx, -2*dotprod*normaly need to be modified (*multiplied by 1 or a sum of 2 values, think 2 due to x,y) in such a way that adding them to Vx and Vy makes resx, resy = linex / y

Write out all those equations and solve them by simply using the general rules to solve linear equation systems. Nothing large nor complex.
Just handwork basically


nino(Posted 2008) [#3]
I learned a lot from this article when I was starting out with physics:

http://www.gaffer.org/game-physics/integration-basics

it's in c++ but easy to convert to bmx


Jake L.(Posted 2008) [#4]
Thanks, I got it.