Rigidbody along with up-vector

I’ve been trying to solve this for the past few days. I’ve been trying to find a good solution to this problem but I cant find any. I’m also new to to Rigidbodies in Unity so any help is appretiated!

Okay, so the thing is I want a RigidBody (Player and almost everything else) to move along different curves in my game.

When working only with the transform, the following code works just fine:

(I’m using my own function here to find out the up-vector at the transform’s position)

// Set the transform.up vector to the curved plane up-vector
transform.up = GridUp (transform.position);

But when trying to modify the RigidBody rotation to the up-vector, the result is wierd. Also when reading other posts one should not chnage the rigidbody rotation and position directly, but instead use the AddForce() and AddTorque() funcions.

My questions is:
How do I rotate a RigidBody to a specific up-vector, and keep the functionality of the RigidBody physics?

Example picture: Moving a rigidbody box along a slope (Red arrow) with rotation around the slope y-axis (Green arrow)

Use Rigidbody.AddTorque:

using UnityEngine;
using System.Collections;

public class Example : MonoBehaviour {

    //apply this script to the object you want to turn
    Rigidbody rbody;
    void Start()
    {
        rbody = GetComponent<Rigidbody>();
    }
    void Update ()
    {
        rbody.AddTorque(new Vector3(0, 1, 0));
        //play with the X, Y, and Z values to get the rotation you want
	}
}

Hope this can help!

I found the answer in another thread:

Works like a charm!