0
\$\begingroup\$

I'm coding a physics engine in Javascript. Forces, Gravity, Friction, AABBs are taken care of. Now, the big question: how do I respond to AABB collisions? Right now, when an object collides, it prints "collision!" in the console.A box falls through the floor, printing collision in the console What formulas and/or techniques are the fastest?

this runs in the render loop (object is the object currently getting looped):

      //AABB STUFF
      EasyPhysics.Objects.forEach(function (object0, index0){
        if(object.getAABB(object0)) {
          object.position.x-=object.force.x;
          object.force.x = 0;
          object.position.y-=object.force.y;
          object.force.y = 0;
          object.position.z-=object.force.z;
          object.force.z = 0;
        };
      });
\$\endgroup\$
3
  • \$\begingroup\$ I presume you started by searching for past answers in the collision-resolution tag? What have you tried based on the research you've done thus far? \$\endgroup\$
    – DMGregory
    Commented Jun 5, 2022 at 21:10
  • \$\begingroup\$ I have tried looking through the code of other people's games, forums, tutorial websites, etc. \$\endgroup\$
    – Andrey
    Commented Jun 5, 2022 at 21:43
  • 1
    \$\begingroup\$ Great, so you've probably already found everything we could tell you. AABB collision resolution is not a new problem, and there's no new secret way of solving it different from what you can already find explained in dozens upon dozens of existing answers and tutorials. So you should be good to go with what you've already found. If you've had difficulty implementing one of the solutions you've found. edit your question to show the code you've written to try to implement it, and explain how exactly it's going wrong for you. \$\endgroup\$
    – DMGregory
    Commented Jun 5, 2022 at 21:45

0

You must log in to answer this question.

Browse other questions tagged .