Box3 AABB Collision problem

Hello, awesome THREE.Community
I have a weird problem, not entirely sure it fits this forum. If its too stupid, please let me know and I’ll remove it.
I made a scene where Obj1 interacts with other meshes, using Box3.intersectsBox() method.
I have an algorithm in my update method that runs every frame:

  1. Save the position of Obj1 to a variable ( by using .copy( ) method )
  2. Move Obj1 according to user input
  3. Iterate through an array of collidable meshes to see if bounding boxes intersect
  4. If Intersection happened, then Obj1 position is restored to the saved variable before any transforms.

What I expected to get is that the object will move freely, but when collision occurs, then the translation is not allowed. However theory and practice are different and once the intersection happens, Obj1 gets “stuck” in the mesh it intersected with, as if its position hasnt been reverted.
I managed to recreate the issue in this codepen:

Later I implemented a list of 5 last positions ( currently in the codepen ), and they all seemed to work as expected, except the last position, just like in the described algorithm. Second last position works but its very “jumpy” and doesnt seem like the right solution.

The problem is in your Player.update() method. It has to look like this:

update( time ){
    this.updateMovement( time );
    this.body.BBox.setFromObject( this.body );

As you can see, you have to update the AABB before you perform the collision detection test. Otherwise the bounding volume does not reflect the current position of the player. After checkCollision(), you can safely update the helper.



Oh my god, you’re right. That was so obvious. Thank you so much!