Hello Guest

Author Topic: Advanced Collider Shapes Workflow  (Read 5979 times)

pako

  • 2D Toolkit
  • Newbie
  • *
  • Posts: 17
    • View Profile
Advanced Collider Shapes Workflow
« on: October 07, 2017, 08:19:07 pm »
Hi,

I want to use Advanced Collider Shapes, in order to have multiple colliders per sprite in a Collection that will be used for creating an Animated Sprite. So, as the Sprite animates and changes shape, the corresponding colliders will be enabled to approximate the sprite's shape in each animation frame.

I was able to create 4 Advanced Colliders per Sprite in the Collection by following the relative documentation: http://2dtoolkit.com/docs/latest/advanced/advanced_collider_shapes.html
but I haven't found any info in the documentation about the Advanced Collider Editor.  Also, it says that "At runtime, the collision shapes for a sprite can be obtained from the tk2dSprite.CurrentSprite.customColliders array." However, there are no examples on workflow and usage, and I really need some help on implementing this feature.

After I created the Animation from the Collection, I created a Sprite with Animator in the scene, and the added Sprite had a Polygon Collider, which I deleted, and I understand that I will have to add the colliders myself, but I don't know how to use the shapes that I created for each sprite in the Collections to help me add the correct shaped collider on the animated sprite.

I also don't know how to use the tk2dSprite.CurrentSprite.customColliders array to enable/disable the correct collider for each frame of the animation.

Your help will be very much appreciated.



unikronsoftware

  • Administrator
  • Hero Member
  • *****
  • Posts: 9709
    • View Profile
Re: Advanced Collider Shapes Workflow
« Reply #1 on: October 09, 2017, 02:21:35 pm »
Hi,

The advanced collider system was created for a particular customer who was using it for a fighting game - basically they wanted to use it to mark hit boxes on the character. What it does is it lets you create the shapes in the editor but doesn't do anything further than that with the data.

You will have to write code to create the colliders at runtime. "The data isn't used by the actual runtime, but you can hook into the system to tell you when the sprite (and as a result the attached colliders) have changed. Please note that the system will not create the colliders for you - you will be responsible in doing that should you wish to create colliders."

To get you started, here's a script that will create and destroy colliders at the correct positions. Its not complete, so doesn't respect rotations. And you should really pool these.

pako

  • 2D Toolkit
  • Newbie
  • *
  • Posts: 17
    • View Profile
Re: Advanced Collider Shapes Workflow
« Reply #2 on: October 09, 2017, 06:56:49 pm »
Thank you for your prompt response.

Your script has been very helpful both for understanding how the system works, as well as to get me started on a full implementation.

It seems to me that for best performance I should turn this into an Editor script to create all colliders for a particular sprite in Edit mode, and then at runtime enable/disable the set of colliders corresponding to a particular animation frame.

As we are on this topic, could you please give some insight on the usage of the Input Box at the top of the Advanced Collider Editor. Apparently it's for the new naming feature, which was added in the last version of 2DTK.  It gets filled with strings, and you can select which one is active by clicking on the checkbox next to it.  What is the correct usage of this feature?

Thanking you in advance.

unikronsoftware

  • Administrator
  • Hero Member
  • *****
  • Posts: 9709
    • View Profile
Re: Advanced Collider Shapes Workflow
« Reply #3 on: October 10, 2017, 09:33:01 am »
The name dropdown was built so you could have shared names whilst avoiding typos in the different colliders that were added. This is so if you were moving a hand collider you could move it rather than destroy (disable) and re-create it. The tickbox selects the collider currently being edited.

In terms of performance, I would just write a simple script to pool initally (create if not exists, or disable when not needed). Depending on your use case, editor scripts might not be necessary.

pako

  • 2D Toolkit
  • Newbie
  • *
  • Posts: 17
    • View Profile
Re: Advanced Collider Shapes Workflow
« Reply #4 on: October 10, 2017, 11:21:47 am »
Thank you!