C# Coding problems...

I am working on my first game ,which is a 2D platformer, and its being coded in CSharp. My player character was given a Rigidbody2D and when I went to go code the movements for the player it didn’t work.

Now, I was following instructions to a tutorial I followed for 2D platformers and I noticed the problem. I noticed that there was a bit of a difference with what he had and what I had. Their Rigidbody2D had a lower case “r”, they written “rigidbody2d**.velocity**”. I tried to write the same thing and it wouldn’t work. I have everything set up a similar way in my script but nothing is working for the script. Can someone please help me?

Did you turn off annotations? It states that the way that it’s accessed has changed in Unity 5.

Link.

Try GetComponent().velocity instead.

As of recent, Unity removed a ton of previously accessible fields.

ok thanks i’ll try it

I did not see that lol. I turned off annotaions. thanks for that

//For Unity 5:

Rigidbody2D Avatar;

void Awake(){

Avatar = GetComponent<Rigidbody2D>();
}


void FixedUpdate()
{
            Avatar.MovePosition((Vector3.MoveTowards(this.transform.position, NewClosePosition, MoveSpeed * Time.deltaTime));}

Maybe don’t call it avatar, if you ever need to use the actual avatars there’s just another level of confusion

1 Like