Search Unity

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:
    1,501