rigidbody2D.velocity

Hey guys , I’ve been following a tutorial and then in the code says to move the player use
private Vector2 movement;
rigidbody2D.velocity = movement;
but in unity 5 give a error in .velocity
what is the replace of that
plase help

In Unity 5 you now need to fetch the Rigidbody2D by using GetComponent.

Also, you want to cache the RigidBody2D in Awake or Start, like so:

Rigidbody2D rb;
Vector2 movement;

void Awake()
{
    rb = GetComponent<Rigidbody2D>();
}

void FixedUpdate()
{
   //Then whenever and wherever(in this class) you want to use the rigibody, you can do like so:
   rb.velocity = movement;
}

You absolutely don’t want to call GetComponent on every frame (in Update or FixedUpdate)…

thanks, I’ll try it when I get home

thank you it workked :slight_smile: ,how I can mark it as resolved

You can’t. Not in the forums anyway. You can only in the Unity Answers section.

You can only like posts or reply saying your problem is fixed.

Glad it works.

You can change the thread title and add [solved] to it. :slight_smile: