Jump to content

I need help with SAT response


Pryme8
 Share

Recommended Posts

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.
 

Link to comment
Share on other sites

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.

Link to comment
Share on other sites

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.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

Loading...
 Share

  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...