Forum rules - please read before posting.

[SOLVED] collider rotates when character turns/walks

edited August 2014 in Engine development
I just discovered a big bug in topdown mode: when a character turns to face an object or walks to a marker, their collider flips from the Z axis back to the Y axis.

This has probably been going on for a while, but only my main characters so far have done walking/facing, and they don't have a hotspot script attached to them, so I didn't notice. But now I'm running into this issue with an NPC, and when he turns, the hitbox for his hotspot becomes really tiny at his feet (because the collider has flipped upright).

I'm using 2D Topdown mode, the characters all have a capsule collider but no rigidbody. (I tried adding the rigidbody again and freezing the rotation on it but that didn't work).

Comments

  • I can't recreate the issue (behaviour works as normal for me), but I'm not sure what you mean by flipping from the Z axis back to Y.  Could you post shots?

    In top-down 2D mode, colliders should indeed rotate.  The inner workings is basically that they behave exactly as they do in 3D mode, only the sprites (which are child objects) are locked to face the camera.

    A shot of the NPC inspector would help, too.  Have you placed the Hotspot on the root object?
  • edited August 2014
    Hey Chris, I made a Vine of it, hopefully you can extract enough from that.

    First there's a shot of the NPC script.
    Then a shot of the Cutscene (basically: NPC teleports to marker > changes order in layer > faces the player > resumes her idle animation).
    The last shot you can see the problem in action in the scene view.


    The culprit is the Face Object action, that's the one that causes the collider to rotate up as if it was a regular 2D game instead of topdown 2D. The same thing happens if I use Character: Move To Point.

    I've worked around it now by explicitly starting the idle_R animation, giving her the appearance of having turned to the right while actually still facing downwards, but being able to use the Face Object action properly would be nicer. Hope you can help.
  • edited August 2014
    OK, this is actually a big problem.

    So: once the Collider rotates like that, it's actually now in the CORRECT position.  The Collider should always run along the Y-axis - the reason being that this causes collisions to only occur at a Character's feet; when navigating a scene, other Colliders shouldn't block the head, for instance.

    You'll need to amend your prefab(s) so that Colliders run along the Y-axis.  This shouldn't be too big a problem: once done, they should behave properly.  What's more of a concern is that this'll reduce the "clickable area" of the NPC to just their feet, since that's all the Collider covers.

    I'm going to have to put my hands up and call this a big oversight on my part.  In my haste to get a viable 2D solution going (before Unity's own 2D tools were released), I overlooked this.  There's no elegant way to get around this, so you'll have to do one of two things, I'm afraid:

    1) Don't correct the prefab, and explicitly state which animation to play, as you are now.
    2) Correct the prefab, and use Hotspots prefabs in place of the NPC's "internal" Hotspot.

    Neither of these are particularly ideal, I apologise.  In truth, I would recommend switching to the "Unity 2D" method, since it's faster and more in line with Unity's internal 2D workflow.  But the above options should provide a workaround, nonetheless.
  • Hey thanks for the reply Chris. For now making do with the animation workaround will be fine, but I think I'll eventually switch this project to Unity2D too. I thought about switching to Unity2D mode about three weeks ago, but with the deadline today to release a new version of my demo I figured it best not to go wild and break too many things ;)

    I've switched from Topdown to Unity2D in another project and it's not that big of a hassle really, I do prefer that mode, but here I also have a few gamecameras that rely on perspective mode and some 3D tricks, so after the deadline I'll sit down for that and then I'll probably be able to put this issue to bed.
  • You're a good sport!

    One other option (knew there was another):
    Attach a Collider (along the Z-axis, as before) and a Hotspot script to the Sprite Child itself.  This'll "catch" player clicks, and replace the NPC's Hotspot inspector (so transfer the values from one to the other, and place the root object on the Ignore Raycast layer).  The sprite will always be positioned correctly, so any attached colliders should also be.
  • Interesting, will give that a try!
  • edited August 2014
    @ChrisIceBox That's what I did when using 2DTK... the capsule collider at its feet for nav and triggers collisions, and the 2DTK's collider (covering the sprite) for hotspot clicks.

    I've been thinking about using Unity2D for one of my projects... but I'm still not sure. I think I'll miss 2DTK multiple resolution/aspect ratio support and multiresolution sprite atlases :/
  • @MaaS: The "Unity 2D" perspective mode is more in terms of the layout of objects and camera perspectivem, rather than the use of Unity 2D sprites (that's the animation engine, which is separate).  Admittedly it's been a while since I delved into 2DTK, but it should still work with the Unity 2D perspective mode.
Sign In or Register to comment.

Howdy, Stranger!

It looks like you're new here. If you want to get involved, click one of these buttons!

Welcome to the official forum for Adventure Creator.