Hi to all.
Right now i am trying to constrain the rotation of a rigid body in x- axis.but i used this code but the object is shaking when the rotation is applied .
code:
function FixedUpdate ()
{
Input1 = Input.GetAxis(“Horizontal”) ;
Input2 = Input.GetAxis(“Vertical”) ;
var target1 = Quaternion.Euler (rigidbody.rotation.x,0.0,0.00);
var smooth = 1.0;
rigidbody.rotation = Quaternion.Slerp(transform.rotation,target1,Time.deltaTime*smooth);
…
Thanks in advance
raja
Update() uses deltaTime, but FixedUpdate() uses Time.fixedDeltaTime. As a result, if you switch Time.deltaTime for Time.fixedDeltaTime, it should smooth out for you.
Also, if you just want the non-x axis to be zero, it’s much faster to do this:
transform.eulerAngles = Vector3(transform.eulerAngles.x,0,0);
Another way to go is to apply a force slightly above and below the centre of mass using rigidbody.AddForceAtPosition:-
var rightingForce: float;
...
function FixedUpdate () {
var upPoint: Vector3 = transform.TransformPoint(Vector3.up);
var downPoint: Vector3 = transform.TransformPoint(-Vector3.up);
rigidbody.AddForceAtPosition(Vector3.up * rightingForce, upPoint);
rigidbody.AddForceAtPosition(-Vector3.up * rightingForce, downPoint);
}