Search Unity

  1. Improved Prefab workflow (includes Nested Prefabs!), 2D isometric Tilemap and more! Get the 2018.3 Beta now.
    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. Let us know a bit about your interests, and if you'd like to become more directly involved. Take our survey!
    Dismiss Notice
  4. Improve your Unity skills with a certified instructor in a private, interactive classroom. Watch the overview now.
    Dismiss Notice
  5. Want to see the most recent patch releases? Take a peek at the patch release page.
    Dismiss Notice

Make Cube flip on its side on GetKeyDown input C#

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

  1. Dargiie

    Dargiie

    Joined:
    May 24, 2018
    Posts:
    1
    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.         {
    3.  
    4.             transform.Translate(0, 0, movespeed * Time.deltaTime);
    5.          
    6.  
    7.         }
    8.  
    9.         if (Input.GetKeyDown("d"))
    10.         {
    11.             transform.Translate(0, 0, -movespeed * Time.deltaTime);
    12.  
    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

    AlanMattano

    Joined:
    Aug 22, 2013
    Posts:
    884