Search Unity

Input concatenated into transform.Rotate

Discussion in 'Scripting' started by scevvin, Aug 29, 2021.

  1. scevvin

    scevvin

    Joined:
    Dec 8, 2020
    Posts:
    8
    Hey all!
    Brand new to coding and I'm obsessed and loving it. I have a question: I noticed that I can write the line below and it still works fine.

    Code (CSharp):
    1. public Rigidbody boardRb;
    2.  
    3. boardRb.transform.Rotate(Vector3.left * Input.GetAxis("Vertical") * rotateSpeed);
    Is this correct and can be used throughout my further projects? Or since it's being calculated with Vector3 and a rotate speed variable, will it be filled with bugs as the game gets more complex?

    For even more context, here is the game it's in:
    Pegboard (Counting Prototype) - Unity Play
     
  2. Kurt-Dekker

    Kurt-Dekker

    Joined:
    Mar 16, 2013
    Posts:
    38,745
    WELCOME! We need more folks like you with your attitude.

    The above code should be fine, but let me observe that it is what I consider very hairy code.

    How to break down hairy lines of code:

    http://plbm.com/?p=248

    Break it up, practice social distancing in your code, one thing per line please.

    Putting all the code on one line does NOT make it any faster. That's not a thing.

    Generally, one thing per line helps you in the future when you go back to your game and have to understand it.

    If you want some more awesome coding tutorials centered around Unity, check out these videos.

    Imphenzia: How Did I Learn To Make Games:



    Imphenzia / imphenzia - super-basic Unity tutorial:



    Jason Weimann:



    Brackeys super-basic Unity Tutorial series:



    Sebastian Lague Intro to Game Development with Unity and C#:

     
    scevvin likes this.
  3. scevvin

    scevvin

    Joined:
    Dec 8, 2020
    Posts:
    8
    Thanks a ton for the welcome and response. Yes, that's a very good point. As I was reading your comment, I remembered the "Clean Code" rule about extract extract extract extract.

    And thank you very much for the video links! I'm going through the Junior Programmer course Unity Offers and am almost done with it, so I'll continue on with those ASAP :)
     
    Kurt-Dekker likes this.
  4. Kurt-Dekker

    Kurt-Dekker

    Joined:
    Mar 16, 2013
    Posts:
    38,745
    Also remember there is like ten billion ways to do any one thing, so don't hesitate to try new stuff, and when something happens you don't understand, try to spend some energy to figure it out, but if not, move on, try something else.

    But of all things, DO NOT GET DISCOURAGED.

    Let me throw you this little helper blurb too to go along with any tutorial you ever do anywhere, programming or otherwise.

    How to do tutorials properly:

    Tutorials are a GREAT idea. Tutorials should be used this way:

    Step 1. Follow the tutorial and do every single step of the tutorial 100% precisely the way it is shown. Even the slightest deviation (even a single character!) generally ends in disaster. That's how software engineering works. Every single letter must be spelled, capitalized, punctuated and spaced (or not spaced) properly. Fortunately this is the easiest part to get right. Be a robot. Don't make any mistakes. BE PERFECT IN EVERYTHING YOU DO HERE.

    If you get any errors, learn how to read the error code and fix it. Google is your friend here. Do NOT continue until you fix the error. The error will probably be somewhere near the parenthesis numbers (line and character position) in the file. It is almost CERTAINLY your typo causing the error, so look again and fix it.

    Step 2. Go back and work through every part of the tutorial again, and this time explain it to your doggie. See how I am doing that in my avatar picture? If you have no dog, explain it to your house plant. If you are unable to explain any part of it, STOP. DO NOT PROCEED. Now go learn how that part works. Read the documentation on the functions involved. Go back to the tutorial and try to figure out WHY they did that. This is the part that takes a LOT of time when you are new. It might take days or weeks to work through a single 5-minute tutorial. Stick with it. You will learn.

    Step 2 is the part everybody seems to miss. Without Step 2 you are simply a code-typing monkey and outside of the specific tutorial you did, you will be completely lost.

    Of course, all this presupposes no errors in the tutorial. For certain tutorial makers (like Unity, Brackeys, Imphenzia, Sebastian Lague) this is usually the case. For some other less-well-known content creators, this is less true. Read the comments on the video: did anyone have issues like you did? If there's an error, you will NEVER be the first guy to find it.

    Beyond that, Step 3, 4, 5 and 6 become easy because you already understand!
     
    scevvin likes this.
  5. scevvin

    scevvin

    Joined:
    Dec 8, 2020
    Posts:
    8
    Thank you so much for the encouraging words! Step 2 definitely sounds like something I kind-of do already by writing comments about what each piece of code does.
     
    Kurt-Dekker likes this.