Vector sliding/bouncing
BlitzMax Forums/BlitzMax Programming/Vector sliding/bouncing
| ||
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 |
| ||
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 |
| ||
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 |
| ||
Thanks, I got it. |