I'm using this article for reference. I understand handling the collision aspect, but I can't figure out how to calculate the new velocity once the ball collides with the ramp. Without it the ball just slides down the slope and stops at the bottom, with no horizontal velocity generated from the descent.
The equation mentioned is
tangentialVelocity = velocity – (velocity * normal)normal
Which I've tried as
ball.velocityX = _magnitude - (_magnitude * _normalX) * _normalX;
ball.velocityY = _magnitude - (_magnitude * _normalY) * _normalY;
to no avail.
Here is what I've done so far, which finds how far the ball is intersecting in the ramp and moves it outside.
var _distance:int = FP.distance(circleWorld.x, circleWorld.y, ball.x, ball.y);
var _penetration:int = _distance + ball.radius - worldRadius;
if (_penetration > 0)
{
var _componentX:int = circleWorld.x - ball.x;
var _componentY:int = circleWorld.y - ball.y;
var _normalX:Number = _componentX / _distance;
var _normalY:Number = _componentY / _distance;
ball.x += _normalX * _penetration;
ball.y += _normalY * _penetration;
}