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

Rigidbody2D,Velocity,Smooth,GetComponent,Movement

Discussion in '2D' started by mravich, Aug 1, 2015.

  1. mravich

    mravich

    Joined:
    Apr 19, 2015
    Posts:
    2
    Hello everybody,

    first of all we would like to Introduce ourselves, we are a group of "programmers" - or lets say "enthusiasts" who form a chilled out BLUANT TEAM.
    After a madassfuck chill(Pardon me for the language please) in Blu's garage, we decided to start programming. That moment was THE MOMENT!(Tadadadam). That was about 6 months ago, and up to now we have managed to make couple of very interesting games.
    We started with another editor(Not gonna say name S*****L) and managed to port playable games to android phone and about 2 months ago we started with Unity. By now we fairly understand the concept of programming and what goes where. We have basic understanding of the unity editor(Still listing the manual everyday), but whatever we find after searching for a problem on the Internet we explore deeper so that we understand it. Yeah right hahahhaha.
    We would grately appreciate if you guys could give us some guidance on what we should look for and where.

    We want to make a side scrolling game with an obstacle being spawned and just moving to the left. After adding sprites and making scripts for movement. We noticed that with using

    Code (CSharp):
    1. transform.position = new Vector3 (transform.position.x- speed * Time.deltaTime, transform.position.y , transform.position.z);
    we experience some jittering or how we like to call it "Štekanje". The movement of that object isn't smooth it somehow stops or goes back or something. We searched online and found out that we could also modify the position using the Rigidbody2D.velocity something. Now we understand that there is a Rigidbody2D component to be added to the prefab, and we understand that addforce should be used to decide which vector2/3(x,y,(z)) will be the forces vector. But we don't really understand how to combine those into a code. Doing it that way maybe isn't even the right solution but thats just the second one we are trying yet, so if you have any helpful hints on what to use , we would be thankfull.

    Okay now lets talk it like programmers already!

    Code (CSharp):
    1.     void Start () {
    2.  
    3.         //Here we need to GetComponent<>() so we can get component of the Rigidbody2D
    4.         // How does this transfer into code?
    5.         //It should be defined in Start but what are we missing?
    6.         gameObject.GetComponent <Rigidbody2D> ();
    7.  
    8.     }
    For now these are the only questions we have and we appreciate any comment about whats written above. Every thought is welcome.

    Keep it real and stay strong!

    Bluant Team
     
  2. mravich

    mravich

    Joined:
    Apr 19, 2015
    Posts:
    2
    Okay guys we beileve the solution to Getcomponent is that we need to define a variable in which we will store the Rigidbody2D? so something like this?

    Code (CSharp):
    1. rb = gameObject.GetComponent <Rigidbody2D> ();
    but where and how do we need to define the rb? How should this be defined?
    It should be defined in the monobehaviour with all others defined variables but what type is this?