Search Unity

  1. Megacity Metro Demo now available. Download now.
    Dismiss Notice
  2. Unity support for visionOS is now available. Learn more in our blog post.
    Dismiss Notice

Collaborative First Project

Discussion in 'Getting Started' started by Zoneo, May 6, 2015.

  1. Zoneo

    Zoneo

    Joined:
    May 1, 2015
    Posts:
    85
    Hey guys!

    I've been playing around in Unity for a little while now, and have come to a point where i feel the biggest thing holding me back from being able to create the programs i desire is my understanding of C#. I've been searching tutorial after tutorial but I really just don't want to sit through any more videos of someone going through and explaining the entire dictionary and what each word does. Through life experience i have come to find that I learn better with a more "hands-on" approach.

    So I was wondering if maybe one of the more experienced members of the community wouldn't mind taking me under his/her wing, so to speak, and creating a game with me so i can learn in a more hands on environment with someone to sort of get me in the right direction and guide me.

    Any and all advise on C# or C# tutorials would be greatly appreciated.

    Thanks!
     
  2. narf03

    narf03

    Joined:
    Aug 11, 2014
    Posts:
    222
    For programming, u need to force yourself to do something, simple, useless, junk, doesnt matter, u must do something to learn programming, like make a simple space invader or something. If you dont know the simple basics, dont even expect to understand a real project, which is alot more complex, 1000x much more coding.
     
  3. Zoneo

    Zoneo

    Joined:
    May 1, 2015
    Posts:
    85
    I just don't know the language so I have a hard time at actually getting it to do what i want it to... like currently im trying to get a prefabbed character to walk in a little "tester" i made, and im using the same code i used for a different player controller, but its not working the way i thought it would... originally. the script cause a ball to roll in the direction on the key press. in this new program, i am trying to get the character to move. Understanding that I dont have animations for the character, i expected him to kind of "hover" across the ground... but he just stands there until he falls over, and then he begins to roll a little more with the key press.


    The way i look at it, my code is apparently designed only for sphere-like objects. so what about my code needs to change, in order to make it work?

    I got the code from Unity's "Roll-a-ball" Tutorial.

    using UnityEngine;
    using UnityEngine.UI;
    using System.Collections;

    public class Playercontroller : MonoBehaviour {

    public float speed;
    public Text Counttext;
    public Text Wintext;

    private Rigidbody rb;
    private int count;

    void Start ()
    {
    rb = GetComponent<Rigidbody> ();
    count = 0;
    SetCounttext();
    Wintext.text = "";
    }


    void FixedUpdate ()
    {
    float moveHorizontal = Input.GetAxis ("Horizontal");
    float moveVertical = Input.GetAxis ("Vertical");

    Vector3 movement = new Vector3 (moveHorizontal, 0.0f, moveVertical);

    rb.AddForce (movement * speed);

    }

    void OnTriggerEnter(Collider other)
    {
    if (other.gameObject.CompareTag ("Pick up"))
    {
    other.gameObject.SetActive(false);
    count = count + 1;
    SetCounttext ();
    }
    }
    void SetCounttext ()
    {
    Counttext.text = "count: " + count.ToString ();
    if (count >= 8)
    {
    Wintext.text = "You Win!";
    }
    }
    }
     
  4. narf03

    narf03

    Joined:
    Aug 11, 2014
    Posts:
    222
    Whats your speed value ?
     
  5. Kiwasi

    Kiwasi

    Joined:
    Dec 5, 2013
    Posts:
    16,860
    Try switching out AddForce for MovePosition. Alternatively you could Transform.Translate

    Add force is basically pushing something. You push something tall, like a model, and it will tend to fall over instead of move.
     
  6. Zoneo

    Zoneo

    Joined:
    May 1, 2015
    Posts:
    85
    i changed the speed to ten and he started to behave more like the ball did, then i changed AddForce to MovePosition and now it seems to move the way i want it, but i can only go in a square within a certain distance (directly related to the speed value) and then when i release the key it brings it back to its starting location
     
  7. Zoneo

    Zoneo

    Joined:
    May 1, 2015
    Posts:
    85
    using UnityEngine;
    using System.Collections;

    public class Playercontroller : MonoBehaviour {

    public float speed;

    private Rigidbody rb;


    void Start ()
    {
    rb = GetComponent<Rigidbody> ();
    }

    void FixedUpdate ()
    {
    float moveHorizontal = Input.GetAxis ("Horizontal");
    float moveVertical = Input.GetAxis ("Vertical");

    Vector3 movement = new Vector3 (moveHorizontal, 0.0f, moveVertical);

    rb.MovePosition (movement * speed);
    }
    }



    is the new code im using. it is a new one all together from the original (the original wasnt imported to the project)
     
  8. BFGames

    BFGames

    Joined:
    Oct 2, 2012
    Posts:
    1,543
    It is because you set your move position based on your inputs. However MovePosition does NOT add to your current position but sets your position equal to the vector you feed it.

    You need to add to your position. So you need to add movement * speed to your current position. like:

    Code (CSharp):
    1. rb.MovePosition(transform.position + (movement * speed));
    On another note then learning C# is great. But make sure you learn programming and not syntax. There is a big difference. Try and learn about if statements, variables, loops, classes and other basic stuff that will be useful for all programming you will ever do.
     
  9. Zoneo

    Zoneo

    Joined:
    May 1, 2015
    Posts:
    85
    After adding that to my code, my guy now moves MUCH faster and uncontrollably (even at speed = 1) and eventually falls over if i change direction...

    do you know any good places to learn those things?

    EDIT: i was able to fix the falling by freezing the y position and XZ rotations
     
  10. narf03

    narf03

    Joined:
    Aug 11, 2014
    Posts:
    222
    if 1 is too big, then slice the "1"
     
  11. Kiwasi

    Kiwasi

    Joined:
    Dec 5, 2013
    Posts:
    16,860
    If you are using move position instead of add force, you probably want a Time.deltaTime in there.
     
    NomadKing likes this.
  12. Zoneo

    Zoneo

    Joined:
    May 1, 2015
    Posts:
    85
    see this is where i get stuck.. i just dont know the language well enough to be like "oh! i'll throw this in here and that ought to do it.. maybe add this here... and were done!" are you guys just doing the index search on move and it tell you all this? or how do you guy know/learn the language itself?
     
  13. BFGames

    BFGames

    Joined:
    Oct 2, 2012
    Posts:
    1,543
    Learning the API for Unity is something you learn as you go.
    What you need to learn is overall programming and overall programming and math related to games.

    When you know that, then you also know what you need to do X or Y, and then you know what to search for. Its not at all about just learning and language, its about learning programming.

    Becoming decent at programming takes times. Code something everyday (not based on copying form tutorials or others code) for at least 2 hours every day. Then in a few years you will be a decent programmer. Sadly it is not possible to cheat in this manner. Its the same as with all other trades.
     
  14. Zoneo

    Zoneo

    Joined:
    May 1, 2015
    Posts:
    85
    NomadKing likes this.
  15. BFGames

    BFGames

    Joined:
    Oct 2, 2012
    Posts:
    1,543
    Thats a very good start :)
     
  16. Toddius

    Toddius

    Joined:
    May 12, 2015
    Posts:
    1
    Zoneo, I know what you mean. I've gone through those beginner scripting videos, coding for absolute beginners, other youtube videos, the first two game tutorials, etc.

    However, I don't seem to be retaining much of it at all other than the overall concept of declaring variables and modifying those through functions (if that's even wrong, I'm in real trouble haha). When I went to start a brand new project to just build a super simple platformer, I couldn't even get my ground to change color through C# after going through these message boards and google for help. Pretty frustrating, I hope at some point it just clicks, because I assumed it was a matter of finding the proper syntax in the index, but that didn't seem to work no matter the variations I typed.
     
  17. BFGames

    BFGames

    Joined:
    Oct 2, 2012
    Posts:
    1,543
    Its training, training, training - as it is with everything else. It takes years to become a decent programmer. Thats why people spent 5+ years at universities to learn the trade.

    However with tools like Unity you can make simple games with a very small amount of coding knowledge. So keep trying to learn how to do basic programming everyday for a few months, and then i am sure you get the hang of it.

    Can see a lot of people struggling with it though. So think i am gonna do a small tutorial with focus on the programming aspect as soon as i am done with my master thesis this month :)
     
  18. Kiwasi

    Kiwasi

    Joined:
    Dec 5, 2013
    Posts:
    16,860
    That's pretty much the heart of programming.

    Just thought I'd post some assurance that you are on the right track.
     
  19. narf03

    narf03

    Joined:
    Aug 11, 2014
    Posts:
    222
    Thats how everybody starts, sorry to say that not everybody is talented to be a programmer, you might spend months into it and noticed that u arent capable to be 1. You need to be good at logic and common sense to be a programmer.
     
  20. Kiwasi

    Kiwasi

    Joined:
    Dec 5, 2013
    Posts:
    16,860
    Just good logic. Common sense is why we hire producers and managers. Common sense can get in the way of good programming.
     
  21. narf03

    narf03

    Joined:
    Aug 11, 2014
    Posts:
    222
    I would say common sense is a critical requirement too, like use what variable type, which database to pick, which loop to use, what algorithm will be the best, when to start asking for help, how to separate a program into multiple modules. Many decisions that the programmer should answer himself.
     
  22. Kiwasi

    Kiwasi

    Joined:
    Dec 5, 2013
    Posts:
    16,860
    Pure logic. There is a defined set of reasons to choose each type, variable, loop and algorithm. For every defined problem there is a correct answer.

    Common sense is for things like: "Don't put your hand on the hot element", "Get some sleep instead of finishing that code, you'll function better in the morning", and "We can't afford to spend the next six months refactoring the code base to use proper design patterns. It ships tomorrow or nobody gets to eat". This type of wisdom is not required to program, and often works against it.

    In fact, common sense would indicate that the gaming market is saturated, and there is a far more stable and reliable income to be made doing databases for banks or something.

    Common sense would also tell anyone this discussion is pointless. I can code perfectly well, and therefore call myself a programmer. I cannot resist continuing this discussion. Therefore my common sense is lacking. Therefore its not required for a programmer to have common sense.

    I'm on fire with my dodgy inferences tonight :)!
     
  23. AnteUpGaming

    AnteUpGaming

    Joined:
    May 12, 2015
    Posts:
    2
    Hi Zoneo,

    I am in the same position as you however I am probably very far behind you in terms of getting up to speed with Unity...

    have you ever thought about outsourcing the coding element you need on the obvious freelancing websites that are out there? Its just a thought.... that may help you.

    Nice Thread guys.

    Anyway, like I say if you or anyone else in the same boat want to create a "C# study group" for beginners on Skype I am happy to be involved or even co-ordinate if necessary. I've tried to teach myself to learn programming 3/4 times over the last 15 years and lost interest each time.
     
  24. Zoneo

    Zoneo

    Joined:
    May 1, 2015
    Posts:
    85
    @Toddius i know what you mean, i don't even know where to begin on a new project, aside from making mountains and placing a house (which i learned how to do from a youtube tutorial that showed me how to do it step by step -_-) i ended up going back to the roll a ball project and trying to add onto that by adding more levels to it and having it transition from the end of the minigame scene to the start of my "level01" scene.

    i made a new level and placed pick ups just as before, only this time i added a new pick up called "Finish" and is simply a different color block that is placed at the end of the course and is supposed to simply end the level when you pick it up. i set it in a new group, added the code as an IF statement in my player controller that if its a "Finish" obj. to display "You Win!"

    the problem is... when i run the game, my controls are inverted as if my camera is looking backwards (kind of like when you're reversing in a car game.) Truth be told, my camera is totally facing backwards. my hopes is that there is someway i can reorient the game without having to physically move all my game objects to the opposite side (Thinking about it now, i suppose adding the opposite sign to the front of the number would do it, huh?) in addition to the controls being inverted, my finish pick up doesn't display my Wintext when you pick up the object (if you're keeping track, this means that BOTH things i tried adding to the game on my own didnt work...)

    Not to mention the fact that i have absolutely no desire to make a "Roll-a-Ball" game is not helping the situation. On a more positive note, at the end of the minigame scene it does totally start the new level, so that part actually worked. however now my code limits me to only being able to place the same amount of pick ups in each level because as of now its set up so that if count > 8 to display you win. however, the game jumps to the new level before the Wintext even has a chance to be visible. but i have a theory on that.


    @AnteUpGaming im trying not to outsource coding cause that the main thing i want to learn. i did import a character package from the assets store cause i dont know the first thing about 3D design/modeling


    @BFGames Please let me know when you finish the coding tutorial, i'd love to check it out!
     
  25. Kiwasi

    Kiwasi

    Joined:
    Dec 5, 2013
    Posts:
    16,860
    I'm no beginner, but I'd be happy to pop in from time to time to pass on some tips. Let me know.