Rotating character while it is moving.

I am making a game, where the player is a ball. When the players body starts to move, I want it to rotate, so it would look like a rolling ball. Apparently,I tried doing so and it didn’t work.

void FixedUpdate () {
horizontal = Input.GetAxis(“Horizontal”);
vertical = Input.GetAxis(“Vertical”);

Movement(horizontal, vertical);

}

void Movement(float horizontal, float vertical) {
PlayerRigidBody.velocity = new Vector2(horizontal * movementSpeed, PlayerRigidBody.velocity.y);
transform.localRotation = new Vector2(transform.rotation.x + 1, 0); // Here is where I get an error.
}
}

Try using “PlayerRigidBody.AddTorque(float force, ForceMode2D.Impulse)”. To add a rotational force to the rigidbody.

Notice that the force value is a float, because you can only rotate on a single axis in 2D.

Also use Code Tags in your post when posting code snippets: