# Weird Liquid

3 posts

 I tried implementing liquid but now it gives me weird effects like: - Jittering - Condensing into one layer or ball - etc ``` var b:LiquidBall; var b2:LiquidBall var visibleRadius:Number = ballRadius * 1.25; for each ( b in balls ) { //gravity if ( b.v.y < 10 ) { b.v.y += gravity; } b.v.x += -player.speed * .25; // border collision if ( b.y + b.v.y + visibleRadius >= liquidCore.height - 1 ) { b.v.y = 0; b.y = liquidCore.height - visibleRadius - 1; } else if ( b.y + b.v.y - visibleRadius <= 1 ) { b.v.y = -b.v.y b.y = 1 + visibleRadius } if ( b.x + b.v.x + visibleRadius >= liquidCore.width - 1 ) { b.v.x = -b.v.x * .2; b.x = liquidCore.width - 1 - visibleRadius; } else if ( b.x + b.v.x - visibleRadius <= 1 ) { b.v.x = -b.v.x * .2; b.x = 1 + visibleRadius; } //ball to ball collision for each ( b2 in balls ) { if ( b != b2 ) { var d:Number = dist( b.x, b.y, b2.x, b2.y ) var dx:Number = b2.x - b.x; var dy:Number = b2.y - b.y; if ( d <= ballRadius * 1.5 ) { b.v.x = -dx * .1; b.v.y = -dy * .1; } } } b.x += b.v.x; b.y += b.v.y; //rendering liquidData.copyPixels( baseBallData, baseBallData.rect, new Point( b.x - ballRadius, b.y - ballRadius ), null, null, true ); } ``` Is there something I should be doing differently? Your collision resolution looks pretty weird. You don’t depenetrate the balls and you don’t use any information about the collision to update the velocity. I can remember you saying that you don’t want actual realistic ball physics, is that still the case? If so, I’m sure there are plenty guides for something like this. Also, at the you add the velocity to the x and y at the end of the script. In my experience, it is better to first add the velocity, and then do the collision. Since the balls are supposed to be water particles, they don’t have to bounce. Do the ball to ball collision like this: ```b.v.x = 0 b.v.y = 0 if(dx>0) { b.x += idealRadius - dx } else { b.x += -idealRadius - dx } //same for y```