- Home /
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)
Answer by Gamehusky · Aug 23, 2016 at 09:11 PM
I found the answer in another thread:
http://answers.unity3d.com/questions/10425/how-to-stabilize-angular-motion-alignment-of-hover.html
Works like a charm!
Answer by matthrewp · Jul 30, 2016 at 02:51 PM
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!
Thank you for your answer! But the problem is how I should use AddTorque to stablize the RigidBody to a specific vector up direction.
Your answer
![](https://koobas.hobune.stream/wayback/20220612085555im_/https://answers.unity.com/themes/thub/images/avi.jpg)
Follow this Question
Related Questions
How to wall-walk? 2 Answers
smoothly rotate my rigidbody with CapsuleCollider to facing the fall direction 0 Answers
Rigidbody spins out of control when colliding into corner 0 Answers
Can i Move/Rotate triggers without Rigidbodies? And other collider questions. 3 Answers
Pysics not working as expected 1 Answer