Search Unity

  1. Unity 2018.1 has arrived! Read about it here
    Dismiss Notice
  2. Scriptable Render Pipeline improvements, Texture Mipmap Streaming, and more! Check out what we have in store for you in the 2018.2 Beta.
    Dismiss Notice
  3. If you couldn't join the live stream, take a peek at what you missed.
    Dismiss Notice
  4. Improve your Unity skills with a certified instructor in a private, interactive classroom. Learn more.
    Dismiss Notice
  5. ARCore is out of developer preview! Read about it here.
    Dismiss Notice
  6. Magic Leap’s Lumin SDK Technical Preview for Unity lets you get started creating content for Magic Leap One™. Find more information on our blog!
    Dismiss Notice
  7. 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:
    819