Forum rules - please read before posting.

2D Clickable NPC Collider

edited November 2014 in Technical Q&A
I have to be missing something here. The tutorial states to make a NPC with a circle collider. Done. Now I want to make the NPC a hotspot (clickable). I follow that tutorial as well. The issue is that the mouse has to scroll over the circle collider for the cursor to recognize the character as a hotspot. The circle collider is placed at the feet of the NPC and if I mouse over the body, the hotspot doesn't work.

If I add another collider like a box collider, when the NPC turns the Y rotation changes and this also changes the additional collider's y-rotation making it useless. This doesn't happen if I place the box collider on the sprite object, but then the NPC script is on the parent object and it no longer works for hotspot detection.

This post illustrates the same problem: http://answers.unity3d.com/questions/603186/is-it-possible-to-rotate-a-boxcollider2d.html

How are you guys setting up clickable, moveable NPCs in 2D with adventure creator? Circle colliders seem unaffected by a Y rotation in 2D. All other colliders are.

Comments

  • Are you using Unity 4.6?  I'm sure this wasn't an issue before, but looking into it now, it does look like a problem.  Attaching a Box Collider 2D to the sprite should work - as the character rotates, the sprite remains fixed, yet the collider changes scale.  Odd behaviour, and not one I'm sure is intended by Unity.

    This'll be a critical issue - anyone with 2D NPCs working pre-4.6 got this now?
  • Yes this is on Unity 4.6. After work today I can reinstall 4.5.5 and report back if the same issue is there.
  • edited December 2014
    Chris,

    I get the exact same behavior in 4.5.5. I retested adding the collider to a sprite and it doesn't work as a hotspot. I also noticed that my main character's circle collider also rotates incorrectly with the usage of rotating the y axis.

    The 2D demo does not seem to use anything that would show this issue originally. Is there a specific reason we are rotating y in 2D besides consistency with 3D?

    Interesting read: http://forum.unity3d.com/threads/unity-4-5-2d-colliders-rotation-change.248890/
  • If I add a RigidBody2D and a 2D collider then the collider seems to work as expected with y rotation but in the scene view the wireframe gizmo is wrong. At the very least my cursor scrolls over the original area and detects the NPC as a hotspot. This is still rather misleading especially since the wireframe shows otherwise. I am also worried about running into an issue with this workaround later on.
  • Thanks for the find.  Though the 2D Collider appears to rotate, in my experience this is just a visual quirk of Unity - it's always worked for me despite the appearance in the Scene view suggesting otherwise.

    I will look into the suggestion that a Rigidbody2D is necessary, though.
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.