0
\$\begingroup\$

In Unity2D, can I have a fixed-angle sprite with a non-fixed-angle CircleCollider2D?

I would like to move my character using the circle physics (without fixed-angle), but display him always as if he wasn't rotated (as if he had fixed-angle).

I thought I could just let the collider rotate, and then rotate-back the sprite in the LateUpdate, however since the collider's center isn't 0,0, it "rotates sideway" and doesn't end up in the "original" position.

My knowledge on matrices and quaterions is null, and trigonometry is only slightly above zero, so I'm a bit at a loss... how can I achieve the desired effect?


In order to prevent a X/Y problem, I want to do that since with box colliders sometimes the characters got stuck: if a platform had even just 1 pixel step, the character couldn't walk over it. Also, slopes were a big problem. Changing the collider to a Circle was the obvious consequence; I also tried to detect and add a small vertical speed but it didn't work very well and was becoming a mess.

\$\endgroup\$
1
  • \$\begingroup\$ I don't know Unity, but I think a picture would help. \$\endgroup\$
    – Anko
    Commented May 18, 2014 at 22:48

2 Answers 2

1
\$\begingroup\$

Maybe you can just turn off the SpriteRenderer script so only your invisible collider still there and rotating, then make a new separate Sprite game object just for displaying the character. (Make sure this separate sprite is not a child of your collider or they will still rotate together.) Then attach a script that keep updating Sprite's transform.position to the same of your rotating collider.

\$\endgroup\$
2
  • \$\begingroup\$ Yes, I was on this route lately – didn't work at first for some reason, and I'm debugging that. If I manage to make it work, I'll accept this answer, meanwhile I'll wait for other tips. \$\endgroup\$
    – o0'.
    Commented May 20, 2014 at 18:49
  • \$\begingroup\$ It worked, but I had to set the CircleCollider center to 0,0 and pivot the Sprite instead. \$\endgroup\$
    – o0'.
    Commented May 24, 2014 at 14:14
0
\$\begingroup\$

I`ve created script to set each frame rotation on SpriteRenderer to zero. Works for me.

public class YourObject: MonoBehaviour
{

    public SpriteRenderer spriteRenderer;

    void Awake()
    {
        spriteRenderer = GetComponent<SpriteRenderer>();
    }

    private void Update()
    {
        spriteRenderer.transform.rotation = Quaternion.identity;
    }

}
\$\endgroup\$

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .