Hello Guest

Author Topic: Question about static sprite batcher collider  (Read 8318 times)

Ezro

  • 2D Toolkit
  • Newbie
  • *
  • Posts: 17
    • View Profile
Question about static sprite batcher collider
« on: June 30, 2013, 10:35:52 pm »
Hi all,

I'm currently working on a 2D platformer, and am thinking of using the static sprite batcher for the drawing of the platforms.

The general plan would be to batch together a lot of box colliders (sprites) into a single static sprite batch containing a mesh collider of all of the boxes.

I'm attempting to accomplish this by doing the following, but have had no success with it:

- Create a static sprite batcher
- Create child GameObject sprites, with their individual box colliders
- Select the SSB and select 'Generate Collider = 1, and then commit

Could someone please assist?

Regards,
Ezro

unikronsoftware

  • Administrator
  • Hero Member
  • *****
  • Posts: 9709
    • View Profile
Re: Question about static sprite batcher collider
« Reply #1 on: June 30, 2013, 11:18:39 pm »
There is a sample of how to create a static sprite batcher in the documentation.
http://unikronsoftware.com/2dtoolkit/doc/2.00/advanced/scripting_static_sprite_batcher.html

Ezro

  • 2D Toolkit
  • Newbie
  • *
  • Posts: 17
    • View Profile
Re: Question about static sprite batcher collider
« Reply #2 on: July 01, 2013, 02:36:32 pm »
There is a sample of how to create a static sprite batcher in the documentation.
http://unikronsoftware.com/2dtoolkit/doc/2.00/advanced/scripting_static_sprite_batcher.html

Hi Unikron,

Thanks for the reply.

How would this differ from creating a static sprite batcher 2dtk object, and then adding child sprites to it, all via the hierarchy pane, though?

Regards,
Ezro

unikronsoftware

  • Administrator
  • Hero Member
  • *****
  • Posts: 9709
    • View Profile
Re: Question about static sprite batcher collider
« Reply #3 on: July 01, 2013, 02:47:41 pm »
Sorry, I think I may have misread your question.
Are you creating sprites with custom box colliders on them? What exactly goes wrong?

Ezro

  • 2D Toolkit
  • Newbie
  • *
  • Posts: 17
    • View Profile
Re: Question about static sprite batcher collider
« Reply #4 on: July 01, 2013, 03:02:57 pm »
Sorry, I think I may have misread your question.
Are you creating sprites with custom box colliders on them? What exactly goes wrong?

I created a 2dtk SSB object, and then created a separate 2dtk sprite, in the hierarchy.

For the sprite, I set a box collider (and also tried using a mesh collider), duplicated it 4-5 times and repositioned the clones.

Once everything was set up, I parented them to the SSB object.

My SSB object was set to generate a collider, but when I committed it, no collider was created for it.

Additionally, when I edited it again, the sprites sometimes lost their colliders.


All I'm trying to do is batch together a lot of sprites to use for platforms/walls, that way I can just perform collision detection against that single batch collider, instead of against lots of individual colliders (or any other collision detection means).

Regards,
Justin

unikronsoftware

  • Administrator
  • Hero Member
  • *****
  • Posts: 9709
    • View Profile
Re: Question about static sprite batcher collider
« Reply #5 on: July 01, 2013, 03:18:38 pm »
How are you creating the box collider? Do you have it set up on the sprite itself in the sprite collection? The static sprite batcher only supports that right now - if you add colliders yourself, its not likely to work properly.

Ezro

  • 2D Toolkit
  • Newbie
  • *
  • Posts: 17
    • View Profile
Re: Question about static sprite batcher collider
« Reply #6 on: July 01, 2013, 03:30:28 pm »
How are you creating the box collider? Do you have it set up on the sprite itself in the sprite collection? The static sprite batcher only supports that right now - if you add colliders yourself, its not likely to work properly.

Oh, I see.

I was just creating individual 2dtk sprite objects. I'm not familiar with the sprite collection, yet.  :-X
Are these steps correct?

- Create my source sprites
- Create a sprite collection, and add the source sprites (with colliders)
- Parent the individual sprites to a SSB

Regards,
Ezro

unikronsoftware

  • Administrator
  • Hero Member
  • *****
  • Posts: 9709
    • View Profile
Re: Question about static sprite batcher collider
« Reply #7 on: July 01, 2013, 04:07:25 pm »
Yup that should work. Thats how its set up with the demo sprites.

Ezro

  • 2D Toolkit
  • Newbie
  • *
  • Posts: 17
    • View Profile
Re: Question about static sprite batcher collider & collision detection
« Reply #8 on: July 01, 2013, 04:14:18 pm »
Yup that should work. Thats how its set up with the demo sprites.

Thanks a lot for the help, Unikron.

I also have some follow-up questions about collision.

For collision detection, I see that it's mostly done with rigidbody + colliders.

I was thinking of avoiding rigidbodies, and going with raycasting + colliders for walls, and box intersection for enemies, in an attempt to increase the performance. (All movement being done by transform changes, instead of addForce)

Do you think that this would be advantageous, or would it be better to just stick with rigidbodies?

Regards,
Justin

unikronsoftware

  • Administrator
  • Hero Member
  • *****
  • Posts: 9709
    • View Profile
Re: Question about static sprite batcher collider
« Reply #9 on: July 01, 2013, 04:21:01 pm »
You don't have to use rigidbodies. Raycasting works fine too.

Ezro

  • 2D Toolkit
  • Newbie
  • *
  • Posts: 17
    • View Profile
Re: Question about static sprite batcher collider
« Reply #10 on: July 02, 2013, 05:56:50 pm »
Unikron,

After using the method you outlined, I was successfully able to get the sprite batcher to work as expected.

Thanks again for the help.

Regards,
Ezro