Search Unity

  1. Unity 2018.3 is now released.
    Dismiss Notice
  2. The Unity Pro & Visual Studio Professional Bundle gives you the tools you need to develop faster & collaborate more efficiently. Learn more.
    Dismiss Notice
  3. We've updated our Terms of Service. Please read our blog post from Unity CTO and Co-Founder Joachim Ante here
    Dismiss Notice
  4. Want to provide direct feedback to the Unity team? Join the Unity Advisory Panel.
    Dismiss Notice
  5. Improve your Unity skills with a certified instructor in a private, interactive classroom. Watch the overview now.
    Dismiss Notice

Make Cube flip on its side on GetKeyDown input C#

Discussion in 'Physics' started by Dargiie, May 24, 2018.

  1. Dargiie


    May 24, 2018
    I want the player (cube) to flip on its side in 2 directions when pressing A and D. Right now i have a really basic script for the movement just to test things out. I'm having trouble finding anything which will allow the cube to smoothly flip on its side quickly when moving left and right instead of just shifting there with the script i have now, i hope this makes enough sense, i'm not to experienced with unity so its difficult for me to get more specific

    Code (CSharp):
    1.   if (Input.GetKeyDown("a"))
    2.         {
    4.             transform.Translate(0, 0, movespeed * Time.deltaTime);
    7.         }
    9.         if (Input.GetKeyDown("d"))
    10.         {
    11.             transform.Translate(0, 0, -movespeed * Time.deltaTime);
    13.         }

    Blue cube being the player, the flip would go to the left and right of this platform at a fixed distance, so there are 3 possible "paths" to be moving on. So when press A to flip left, what would be the left side of the cube, would be the side facing the ground and vise versa.
  2. AlanMattano


    Aug 22, 2013