Search Unity

Moving a 2D square by rotation?

Discussion in '2D' started by Spiderwork, Nov 4, 2019.

  1. Spiderwork

    Spiderwork

    Joined:
    Feb 1, 2018
    Posts:
    32
    Hi there,

    is there a way to move a square sprite check_1.png just by using check_2.png rotation?
     
  2. eses

    eses

    Joined:
    Feb 26, 2013
    Posts:
    2,637
    Hi @Spiderwork

    Haven't ever tried this specific thing, but if you are using 2D physics system to move your objects, then there is Apply Force at Position method. In theory, you could apply force to corner of cube so that it flips around: https://docs.unity3d.com/ScriptReference/Rigidbody2D.html

    Let me know if it works...

    Another choice is to just animate it in Unity or in your 3D software to give impression of rolling. There are many mobile games where this kind of animation has been used.
     
    Spiderwork likes this.
  3. Spiderwork

    Spiderwork

    Joined:
    Feb 1, 2018
    Posts:
    32
    I don't understand how to apply force to a corner, but anyway, I found a solution: I rotate it and move it at the same time. I'm also turning FreezeRotation.Z on when moving and when player is not running, I turn it off - then the rotation is going down correctly!

    But thanks for your answer (sorry for my bad english)!
     
  4. blu3drag0n

    blu3drag0n

    Joined:
    Nov 9, 2018
    Posts:
    94
  5. JosephMGS

    JosephMGS

    Joined:
    Nov 5, 2019
    Posts:
    20