[Math] Acquire angle from collision

No idea how to word this, so I will go ahead and draw it.

I am using Box2D, however it is not really working out to well due to the physics literally being too accurate lol, so I need to cheat and instead control the balls velocity myself…

http://s26.postimg.org/pf881ij7t/needthis.png

I need the angle of that impact, the problem I have is that even with restitution set to 1, friction to a low number…the ball will still gradually slow down, sometimes if it hits a block just right it can almost bring it to a stop.

This is with a low density ball and a high density brick, the paddle is held in place by a joint so it bounces off that fine.

My idea is to just get that angle, transform the body to that angle and then use cos/sin to apply a velcoity. I will probably move away from Box2D if it turns out bad.

What about using friction 0f, and density 1f for all objects?

Other than that, for axis aligned boxes, you can just take a point of the path previous to the collision, and mirror the x-component at the collision axis, e.g. ball is at Xprev=20;Yprev=10 the frame before the collsion, at Xcol=25;Ycol=5 right at the collsion, so it should be at Xnext=30;Ynext=10 the frame after the collision. This can be calculated with Xnext=Xcol+(Xcol-Xprev);Ynext=Yprev.

For non-axis aligned boxes you need to get yourself up to speed with 2D vector math, dot products and normals.

The ball becomes very linear and boring, you can’t like “slice” it with the paddle to control direction :(.

Yeah I have done something like that before but was looking for something a little more complicated for a better feel

Annnnd that is the complicated part, do you have a good resource? I understand vector math besides those 2 things you just stated lol.

It’s simply a reflection.

Angle between reflected path and old path is equal to 2 times the angle between the normal of the surface and the path vector that will be reflected.

http://higherorderfun.com/blog/2012/06/03/math-for-game-programmers-05-vector-cheat-sheet/

Hmm, maybe make the ball high density and the paddle low density instead? I didn’t use Box2D before, but cant you accellerate the ball in reaction to a collsion event to overcome the velocity loss?

You don’t need angles. The aligned case: normal of surface (aligned to world), out vector = negate parallel part of incoming and the remain part stays the same. Non-aligned case: the same. You just need some more math to compute it.

The guys to made N+ wrote an couple of articles on how they did the physics:

You’re going to be most interested in the early section here, Bounce and Friction:
http://www.metanetsoftware.com/technique/tutorialA.html

They simply resolve collision by reflecting the ball’s velocity with two multipliers, bounciness and friction.

For axis-aligned cases like your example diagram in the OP, this is very simple: (f is the friction coefficient, b bounciness)

How exactly you sum the velocities when two moving object collide is partly a matter of preference as to what looks or ‘feels’ good, but for most accuracy you’d want to use momentum to resolve.

If you simply set bounciness (restitution) and friction to 1.0, then the ball will never slow down.

Thanks for all your replies, I have reviewed my choices and I am chucking Box2D out of the window as it is simply not needed.

I like your post BurntPizza.