Behavior: Scale collision boxes with Actor

Greg

  • *
  • Posts: 1260
As you may know, when you scale an Actor up or down using the "grow by" block - this doesn't do anything with the collision shapes.

I'm working on a behavior that will allow you to sync up the collision shape with the size of the Actor.  Here's a quick demo.

<a href="http://static.stencyl.com/games/2119-5.swf" target="_blank" class="new_win">http://static.stencyl.com/games/2119-5.swf</a>

« Last Edit: April 27, 2011, 08:05:24 am by Greg »

Jon

  • *
  • Posts: 17524
Great job! Reminds me of something from Yoshi's island.

Greg

  • *
  • Posts: 1260
Thanks guys, this now seems to be working for single shape and multiple shape animations for boxes, circles, polygons.

The only case that doesn't work as expected is having a circular collision shape that is not in the very center of the Actor.  I can't find a way to move a circular fixture around like I can with polygons, so I'm going to table this piece for now.  Not sure how big of a deal that is anyway.

Greg

  • *
  • Posts: 1260
Ok the behavior is up on Forge.  I may work on it again when I have more time, but maybe not.

Behavior name: Scale Collision With Actor

Joe

  • *
  • Posts: 2480
That is awesome! I didn't know it was possible to rescale the collision shapes without confusing Box2D.

Greg

  • *
  • Posts: 1260
Thanks Joe - at first I was going to try to just kill the body and recreate the scaled version of it - but I found that it was possible to just move the vertices around.  I'm not sure if Box2d technically likes this, but it has seemed to work out fine so far :)

Jon-iPad

  • *
  • Posts: 166
Thanks Joe - at first I was going to try to just kill the body and recreate the scaled version of it - but I found that it was possible to just move the vertices around.  I'm not sure if Box2d technically likes this, but it has seemed to work out fine so far :)

 Do you have to call any reset function to confirm the "change" or does it automatically work?

Jon-iPad

  • *
  • Posts: 166
Because right now, region resizing uses the destroy and remake method. I wonder if this approach would make more sense.

Greg

  • *
  • Posts: 1260
Right now it just works automatically when I update the vertices.  I can try to look into it for regions.

Jon

  • *
  • Posts: 17524
That would be terrific, but if you find it regresses (stuff like it stops detecting collisions after you resize), then we'll stick to what we have today.

Stencyl Ninja

  • Posts: 246
I can't find this on the Forge and it looks awesome .... where can I get it?

captaincomic

  • *
  • Posts: 6109
I think you don't need a behavior for that anymore. There's a switch in the actor physics settings to scale collision boxes when using the grow block.

Stencyl Ninja

  • Posts: 246
Sweet ... I didn't notice that, thanks!