Hello Guest

Author Topic: BoxTrimmed + Animated Sprite + CharacterController = Uneven pace when moving  (Read 3504 times)

Ubahs

  • 2D Toolkit
  • Newbie
  • *
  • Posts: 6
    • View Profile
Hi there,
I have a walk animation that uses multiple sprites of varying widths.  The problem is that the automatic trimmed box alongside the CharacterController's .Move causes the animation and movement to lurch along with the varying sizes.  While amusing, it's not what I'm trying for.

I'm hoping to not manually pad those particular sprites, or have to add Colliders via code.  But, the SpriteEditor won't let me make a polygon collider larger than the sprites.  And, it seems that UserDefined options are for the sprite in its entirety, not for a few frames of an animation.

It's so close, I just need some way to set the collision box larger than the sprite itself for a couple frames.  Is that possible?

I see all these padding options, but none let me choose a value to pad in there (that I can find).

I tried setting the anchor to lower-left, but that messes with the .Move as well, so that's at Middle-Center like it defaults to.

Any trick to this or should I modify these sprites by hand?

Thank you!



unikronsoftware

  • Administrator
  • Hero Member
  • *****
  • Posts: 9709
    • View Profile
The bounds in the sprite collection editor is constrained in code.
The rest of the system copes fine with bounds being outside the texture space.

In tk2dSpriteCollectionEditorTextureView,
find these lines and comment them out / delete them:

Code: [Select]
// constrain
param.boxColliderMax.x = Mathf.Clamp(param.boxColliderMax.x, 0.0f, tex.width);
param.boxColliderMax.y = Mathf.Clamp(param.boxColliderMax.y, 0.0f, tex.height);
param.boxColliderMin.x = Mathf.Clamp(param.boxColliderMin.x, 0.0f, tex.width);
param.boxColliderMin.y = Mathf.Clamp(param.boxColliderMin.y, 0.0f, tex.height);

This will let you resize your custom box collider outside the bounds of the texture.
If you're animating the collider, then you shouldn't be using polygon colliders anyway - so this will be your best bet.

Ubahs

  • 2D Toolkit
  • Newbie
  • *
  • Posts: 6
    • View Profile
Perfect, thank you very much!