# How to make rigid body move smoothly on uneven platform?

Right now I'm using Rigidbody2d for the game character along with polygon collider 2D(2d platform game).

I'm beginner hope I'm using correct components.

And transform to move character from left to right.

Character.transform.Translate(Vector2.right * speed * Time.deltaTime);


And upward(jump).

Character.transform.Translate(Vector2.up * speed * Time.deltaTime);


When the game character moves on slopes there's lot of friction and bounciness and rotation and its worse when jumping from slopes.

• The answer below about not wanting to use transform.translate is correct, but I suggest you modify the velocity of the RigidBody instead and pass Vector2.up/Vector2.down times the speed only. The implementation of RigidBody will handle the timestep – Athos vk Jan 21 '16 at 12:15

It is recommended to move through Rigidbody so that you can achieve natural behavior.

To do so, you can follow the following simple steps and write the following code in the script attached to your character.

// Class level variable
Rigidbody2D _rb;

void Start()
{
// Assigning rigidbody2d component to variable
_rb = GetComponent<Rigidbody2D>();
}

void Update()
{
// Setting speed along x-axis
_rb.velocity = new Vector2(speed,_rb.velocity.y);

// For now it will jump on strike of space key. Please change it according to your input mehtod
if (Input.GetKey(KeyCode.Space)){
Jump();
}
}

void Jump()
{
// 300 is the jump force. Do change it accordingly.
}

• Should i use AddForce to move rigid body in x axis too? – user75648 Jan 21 '16 at 14:08
• AddForce in Update? Don't even think about it :D – Hamza Hasan Jan 21 '16 at 14:09
• And if you do AddForce in start then gradually your character will get slow down – Hamza Hasan Jan 21 '16 at 14:09
• Then what should i use for smooth movement in x axis? – user75648 Jan 21 '16 at 14:09
• I wrote _rb.velocity = new Vector2(speed,_rb.velocity.y); in update – Hamza Hasan Jan 21 '16 at 14:10

Dont use transform.Translate. it completely ignores collision. Try using rigidbody instead. It will make the movement smoother too

• Can you give an example? – user75648 Jan 21 '16 at 12:19
• After ataching rigidbody, do: Rigidbody2D rb = gameObject.getComponent(Rigidbody2D) and then rb.AddForce() – Bálint Jan 21 '16 at 12:26
• AddForce makes the character rotate and move forward. – user75648 Jan 21 '16 at 12:40
• rb.AddForce(transform.forward * 1000) also, you may neee to cap the speed using rigidbody.velocity.magnitude. There are plenty of tutorials online incuding the unity docs and the original tutorials, you should really look into that – Bálint Jan 21 '16 at 12:45