# 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 Jan 21, 2016 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? Jan 21, 2016 at 14:08
• AddForce in Update? Don't even think about it :D Jan 21, 2016 at 14:09
• And if you do AddForce in start then gradually your character will get slow down Jan 21, 2016 at 14:09
• Then what should i use for smooth movement in x axis? Jan 21, 2016 at 14:09
• I wrote _rb.velocity = new Vector2(speed,_rb.velocity.y); in update Jan 21, 2016 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? Jan 21, 2016 at 12:19
• After ataching rigidbody, do: Rigidbody2D rb = gameObject.getComponent(Rigidbody2D) and then rb.AddForce() Jan 21, 2016 at 12:26
• AddForce makes the character rotate and move forward. Jan 21, 2016 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 Jan 21, 2016 at 12:45