Pryme8 Posted August 31, 2016 Share Posted August 31, 2016 So, I'm sure some of you have heard that I'm working up a web worker and Physics Tutorial... I swear in the end this is gonna be all BJS related... I just gotta get to that point first. Umm Ive kinda ran into a thing that I'm having trouble wrapping my mind around... https://pryme8.github.io/fishsticks/ so I know its glitchy, and I have not told it what to do when both objects have mass that's why it freaks out when the little balls collide... but um how exactly do I get the distance I need to separate my objects after the collision? Core.Test.Circle2Circle = function (a, b, preCalc) { var differenceV = b.position.clone().subtract(a.position); var totalRadius = a.body.radius + b.body.radius; var totalRadiusSq = totalRadius * totalRadius; var distanceSq = differenceV.len2(); if (distanceSq > totalRadiusSq) { return false; } var response = {}; var dist = Math.sqrt(distanceSq); response.a = a; response.b = b; response.overlap = totalRadius - dist; response.overlapN = differenceV.clone().normalize(); response.overlapV = differenceV.clone().scale(response.overlap); response.aInB= a.body.radius <= b.body.radius && dist <= b.body.radius - a.body.radius; response.bInA = b.body.radius <= a.body.radius && dist <= a.body.radius - b.body.radius; return response; } is the function generating the hit results for sphere on sphere action ^_^... umm I have everything I can think of... and tried doing it the way I thought I was supposed to which was take the overlapN and scale it by the overlap... which should give me the amount that the two need to separate... but when I do that the ball makes a HUGE jump off the bottom ball... I scaled the overlap normal by 10 just to see if that would work and it did (for general purposes), but before I start programing in bounciness and friction, was really hoping to get a more accurate separation distance. Quote Link to comment Share on other sites More sharing options...
Pryme8 Posted August 31, 2016 Author Share Posted August 31, 2016 @Wingnut who's our math star? Im starting to think i just need to move it by the overlapV - the radius of the sphere? Quote Link to comment Share on other sites More sharing options...
Wingnut Posted August 31, 2016 Share Posted August 31, 2016 YOU are the current "math star" Pryme8 1 Quote Link to comment Share on other sites More sharing options...
Pryme8 Posted August 31, 2016 Author Share Posted August 31, 2016 that made me want to smile and frown at the same tie >_< **EDIT Figure it out: p = calc.newPos.clone().subtract(hit.overlapV); v = calc.newVel.clone().reflect(hit.overlapN); My collision prediction works for pretty fast moving objects, but ill include the option to do substeps if you need things that are really fast... Convex and Non-Convex Polygon support soon. Wingnut 1 Quote Link to comment Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.
Note: Your post will require moderator approval before it will be visible.