Hello,
I've been trying to implement some simple physics simulation in pixi, involving a ball (circle) that bounces around and spins. I've managed to aproximate a pretty good model myself but the movement always becomes awkward when the ball begin to slow down so I tried to use the Garwin model I found here. However, something must be wrong with either the way I applied the functions or the MUs i'm using because as the ball settles to the floor it begins to accelerate exponentially.
This is my bounce function:
let alfa = 0.4,
cor = {
x: 0.8,
y: 0.8
}
cat.radius = 32;
function enhancedBounce() {
let vx = (((1 - (alfa * cor.x)) * cat.vx) + ((alfa * (1 + cor.x)) * cat.vr * cat.radius)) / (1 + alfa);
let vr = ((1 + cor.x) * cat.vx + alfa * (1 + cor.x) * cat.radius * (cat.vr)) / (cat.radius * (1 + alfa));
cat.vr = vr;
cat.vx = vx;
cat.vy = -cor.y * cat.vy ;
}
Where cat.vx and cat.vy are velocity components and cat.vr is the angular velocity of the ball. Now I'm pretty bad at math but it seems that whatever I input into the functions as vx and vr, the output of both functions is greater than those values (vr' > vr and vx' > vr) which seems counterintuitive to me, however, since I'm not good enough at math I can't demonstrate that this is in fact the case.
cat.vx and cat.vr are just added to cat.x and cat.y on every render
function render() {
if(cat.x >= sceneHeight - 32) {
enhancedBounce();
}
cat.x += cat.vx;
cat.y += cat.vy;
cat.rotate += cat.vr;
}
The function performs well when the ball is simply bouncing off the ground with the rotation and x-velocity looking nice but the moment the ball rests on the ground and enhancedBounce() is called every frame, it accelerates as stated before.
Any idea what i'm doing wrong?