Search code examples
collision-detectionaframewebvr

In A-Frame, how do I give an entity a larger size for collision than its actual size? (using aabb-collider or another)


I have several a-frame entities for which I have collision detection working using Kevin Ngo's aabb-collider. For some of them, I want to detect a "collision" using a bounding box larger than the bounding box based on the mesh. Can I do so using aabb-collider, or should I switch to Don McCurdy's sphere-collider instead? If so, is there example code somewhere?


Solution

  • I'm rather using Don McCurdy's physics engine, but if You have to change Your whole concept it's easier to find a workaround. The API has no property which could change the collision box / object.

    So how about making an invisible object, bigger than yours, and check the collision with it ?

    <a-entity geometry="primitive:box" camera wasd-controls 
    aabb-collider="objects: .collider" comp></a-entity>
    <a-sphere scale="3 3 3" position="0 0 -5"  class="collider"    
    material="color:green;opacity:0.1">
       <a-box color="blue"></a-box>
    </a-sphere>
    

    So, I have my camera, with a box geometry, so i can fly into the sphere, The sphere has the corresponding collider class, and the box is the visible item.

    Working fiddle here. Check out the logs, it prints out the collision events.