How to make collider 2d in spark ar?

guys , i need your help ,

i want to detect when object has been touch that finish line then do something ,

i dont know how to do , please help

in unity i use 2d box collider and detect it using onCollider2d

but idont know how to do it in spark ar …

You can use the axis-aligned bounding box method of hit testing.

var rect1 = {x: 5, y: 5, width: 50, height: 50}
var rect2 = {x: 20, y: 10, width: 10, height: 10}

if (rect1.x < rect2.x + rect2.width &&
   rect1.x + rect1.width > rect2.x &&
   rect1.y < rect2.y + rect2.height &&
   rect1.y + rect1.height > rect2.y) {
    // collision detected!

You will need to translate this into patches, of course.


Do only faces have bounding boxes? The SceneObject is supposed to have one, but I get “undefined” on most of them.

The BB is not available through script yet. Just a get hours ago I was trying to get a solution for this but the best thing is just using the patch bridge. I’d love to see it on the next release but I don’t think that’ll be the case (:sob:)

1 Like

Thank you, I ended up doing this:

const lipPoints = [
    // Find max and min of lip-points for pseude-bounding box
    let maxLipX = lipPoints[0].x.max(lipPoints[1].x.max(lipPoints[2].x.max(lipPoints[3].x)))
    let minLipX = lipPoints[0].x.min(lipPoints[1].x.min(lipPoints[2].x.min(lipPoints[3].x)))
    let maxLipY = lipPoints[0].y.max(lipPoints[1].y.max(lipPoints[2].y.max(lipPoints[3].y)))
    let minLipY = lipPoints[0].y.min(lipPoints[1].y.min(lipPoints[2].y.min(lipPoints[3].y)))
1 Like