Search Unity

  1. Get all the Unite Berlin 2018 news on the blog.
    Dismiss Notice
  2. Unity 2018.2 has arrived! Read about it here.
    Dismiss Notice
  3. We're looking for your feedback on the platforms you use and how you use them. Let us know!
    Dismiss Notice
  4. The Unity Pro & Visual Studio Professional Bundle gives you the tools you need to develop faster & collaborate more efficiently. Learn more.
    Dismiss Notice
  5. Improve your Unity skills with a certified instructor in a private, interactive classroom. Learn more.
    Dismiss Notice
  6. ARCore is out of developer preview! Read about it here.
    Dismiss Notice
  7. 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
  8. 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:
    859