Search Unity

  1. Welcome to the Unity Forums! Please take the time to read our Code of Conduct to familiarize yourself with the forum rules and how to post constructively.
  2. We have updated the language to the Editor Terms based on feedback from our employees and community. Learn more.
    Dismiss Notice
  3. Join us on November 16th, 2023, between 1 pm and 9 pm CET for Ask the Experts Online on Discord and on Unity Discussions.
    Dismiss Notice

First Assignment in Unity

Discussion in 'Getting Started' started by bangsauce, Jun 11, 2015.

  1. bangsauce

    bangsauce

    Joined:
    Jun 11, 2015
    Posts:
    4
    Hey guys I'm a complete novice in Unity and C# but I decided to try it out for my game development class. This is my first assignment.

    "Make a program that creates a cube with three spheres that generate at random locations and random velocities within the cube.
    Gravity is simulated within the cube, and the balls are programmed to be elastic so that they bounce.
    XYZ coordinates are displayed of each ball's position in real time. Additionally, the position of each ball
    is recorded every second to a text file."

    Right now I'm starting from the Roll-a-ball tutorial on the main site, I'm gonna look around this forum for more tutorials/books after. I was wondering if writing the position of each ball every second to a text file would be a problem. Any guidance would be much appreciated!
     
  2. jhocking

    jhocking

    Joined:
    Nov 21, 2009
    Posts:
    813
    How long do you have to complete the assignment? Those things aren't terribly hard, but that's a lot for a first assignment.

    My book Unity in Action would teach you most of what you need to know, although you might need to lookup writing to a text file in C#. I do go over one example where data gets written to a text file, but that's an example of where Unity sends data to a server and then the server writes the sent data into a file. That indirection is probably overkill for your assignment; C# has IO functionality, just lookup System.IO
     
    theANMATOR2b likes this.
  3. bangsauce

    bangsauce

    Joined:
    Jun 11, 2015
    Posts:
    4
    Thanks for the tip, is your book updated for Unity 5 yet? I have about a week and a half to finish the assignment. It was meant to be done in JMonkey and Java, but Unity seems so much cooler.
     
  4. JoeStrout

    JoeStrout

    Joined:
    Jan 14, 2011
    Posts:
    9,848
    This is totally doable. We're not going to do your homework for you, of course, but we can help out if you get stuck!

    Writing to a file is no problem; when using C# you have all the power of (almost) the entire .NET library. So you can google things like "how to write to a text file in C#" and find lots of explanations, tutorials, and sample code.

    For the bouncing spheres, do you need to code the physics (which is reasonably simple for spheres) yourself? Or are you allowed to use the built-in physics engine?

    In the latter case, the only gotcha to watch out for is: you can't put a solid object (like a sphere) inside another solid object (like a cube). Your "cube" container will need to actually be modeled as six boxes, one for each side.

    But once you've got a grip on that, the rest should pretty much fall into place!
     
    Kiwasi and jhocking like this.
  5. bangsauce

    bangsauce

    Joined:
    Jun 11, 2015
    Posts:
    4
    I believe I can use the built-in physics engine, thanks for your help! I will update you guys on my progress.
     
  6. jhocking

    jhocking

    Joined:
    Nov 21, 2009
    Posts:
    813
    Yep! In fact that's the main reason it only just went to the printer, rather than a couple months ago; delayed while I updated everything for Unity 5. Right now it's an ebook.
     
  7. Kiwasi

    Kiwasi

    Joined:
    Dec 5, 2013
    Posts:
    16,860
    Yeah, I started with JMonkey. Unity is miles simpler to use and generally more powerful. Just check in that your lecturer is okay with doing the assignment in a different engine.

    But as to the actual assignment, while it seems like a lot, it would probably take an experienced coder about ten to twenty minutes in Unity. As an absolute beginner you could knock it out in a day.

    Google is the programmers best friend.
     
    Ryiah and NomadKing like this.
  8. bangsauce

    bangsauce

    Joined:
    Jun 11, 2015
    Posts:
    4
    Hey guys, I'm just about finished with the assignment now, the only thing that could be missing is that it doesn't write to the text file live every second. Instead I set up a coroutine that stores the coordinates every second for 5 seconds, and then writes them to the text file.

    If you guys have the time to check it out, I would appreciate any feedback. My professor said we will be making updates to this project in the future, so hopefully you guys can stick around for that too.

    P.S.
    Joe your book "Unity in Action" helped a lot. After reading chapters 1-3 and a bit of 6 for the GUI, it gave me a good base to start from and also helped me better understand the stuff I was Googling. I'm glad I made the purchase!
     

    Attached Files:

    NomadKing and jhocking like this.
  9. jhocking

    jhocking

    Joined:
    Nov 21, 2009
    Posts:
    813
    I'll checkout the project tonight. Glad you found my book helpful!

    You should probably check with your professor early about the storing to a text file; it would be pretty easy to modify your coroutine to write to a text file instead of storing the coordinates for later, so it would be a shame to lose points over that.