Indie game storeFree gamesFun gamesHorror games
Game developmentAssetsComics
SalesBundles
Jobs
0
Members

Trouble getting a list of bodies touching another body [arcadephysics]

A topic by Viko created Oct 07, 2016 Views: 273 Replies: 2
Viewing posts 1 to 3
(1 edit)

This is what I have so far:

function getAllColliding(body: Sup.ArcadePhysics2D.Body): Sup.ArcadePhysics2D.Body[] {
  return Sup.ArcadePhysics2D.getAllBodies()
    .filter((x)=>Sup.ArcadePhysics2D.collides(body, x));
}

let warp = getAllColliding(this.actor.arcadeBody2D)
  .map((x)=>_.tap(x, (x)=>console.info('a ' + x.actor.getName()))) // :(
  .map(function(x) { return x.actor.getBehavior(WarpBehavior); })
  .filter(_.negate(_.isNil))
  .map((x)=>_.tap(x, (x)=>console.info('b ' + x.actor.getName())))
  [0];
if (warp) {
  warp.follow(this.actor);
}

No matter what I try, I have a body that just doesn't show up. It doesn't even reach the line I marked with :(, even though I'm certain they are actually colliding. And yet nonetheless, the body in question is still solid!

Things I've tried:

  • using intersects() instead of collides()
  • swapping the positions of body and x in getAllColliding()
  • doing both of the above things at once
  • deleting and recreating the actor this behavior is on
  • deleting and recreating the actor I'm trying to collide with
  • setting the body-to-collide-with to 1x1 at 0 offset with 0 bounce
  • confirming, via similar log calls, that the body-to-collide-with is being returned from getAllBodies() (it is)
  • setting the body this behavior is on to 1x1 at 0 offset with 0 bounce
  • setting the body-to-collide-with as non-movable
  • setting the body-to-collide-with as movable
  • moving the actor-to-collide-with down the actor list, below an actor that I can work with just fine
  • moving the actor-to-collide-with off of its parent
And I'm kinda stuck.

Update: As a temporary workaround, I can briefly increase one body's size by 0.1 and reinstate the original size after the intersects() check. For obvious reasons, this won't work if I use collides(). This is still pretty fragile, but at least I can collide some of the time.

Update: Turns out to be because of some unexpected behavior from intersects(). I've opened a PR.