Hello Guest

Author Topic: How do i build a box collider at runtime.  (Read 7031 times)

JerryCic

  • 2D Toolkit
  • Newbie
  • *
  • Posts: 11
    • View Profile
How do i build a box collider at runtime.
« on: February 14, 2012, 02:33:41 am »
Hi

I have a sprite in the hierarchy, it has a box collider placed there using the toolkits' edit.
At runtime, i add several other sprites of various sizes to the right of the initial sprite as children.

I can use the bounds extents of all the sprites to create a vector3 that is the extent of the box collider that i want to build.

I can also determine where the center of that collider should be.

I have tried to modify the existing collider, by setting its bounds.extents vector. this did not work.

basically I want a collider that covers the entire set of sprites.

How can i modify the collider or simply create a new collider that essentially will cover the entire set of sprites?

I have a script attached to the parent sprite. the problem is that the script doesnt execute for the children. The script allows the entire group to move its position via mouse or touch drag and drop with glide and boundaries.

If I create a box collider for each sprite, then i would have to place the script in each sprite. That would mess up some of my persistant variables in that live from update to update within each script intance.

I have tried having an empty game object act as the container, as well as trying the polygon convex mesh. I have tried the build() function. I am plugging away but have come up against the wall.

Thanks
Jerry C

JerryCic

  • 2D Toolkit
  • Newbie
  • *
  • Posts: 11
    • View Profile
Re: How do i build a box collider at runtime.
« Reply #1 on: February 14, 2012, 06:27:36 am »
I figured this one out myself.

I was overthinking it. Setting the boxCollider.bounds.extents will not do it.
You have to use these:

tk2dSprite.boxCollider.size
tk2dSprite.boxCollider.center

on the parent sprite.

Jerry
« Last Edit: February 14, 2012, 06:29:57 am by JerryCic »