- Home /
Script doesn't affect rigidbody's values.
I have a script that rotates the box with addTorque. The script works fine, but the box feels "slidely" over the addTorque, so I added some if statements that whenever the player input is 0, the angular drag increases, but the angular drag doesn't change in any way.
Here's the script
using UnityEngine;
using System.Collections;
public class Rigidbody_Controls : MonoBehaviour {
public float amount;
private Rigidbody boxRigidbody;
private float h;
private float v;
private float rigidbodyDefaultAngularDrag;
void Start()
{
boxRigidbody = GetComponent<Rigidbody>();
rigidbodyDefaultAngularDrag = boxRigidbody.angularDrag;
}
void Update()
{
h = Input.GetAxis("Horizontal") * amount * Time.deltaTime;
v = Input.GetAxis("Vertical") * amount * Time.deltaTime;
Debug.Log(h);
boxRigidbody.isKinematic = false;
boxRigidbody.useGravity = false;
boxRigidbody.AddTorque(Vector3.up * h);
boxRigidbody.AddTorque(Vector3.left * v);
if(h == 0)
{
boxRigidbody.angularDrag = 1 * Time.deltaTime;
}
if(boxRigidbody.velocity.magnitude < .9)
{
boxRigidbody.angularDrag = rigidbodyDefaultAngularDrag;
}
}
}
Comment
If the rigidbody is on the same object as the script you can access it by simply using "rigidbody"
Got it... the boxRigidbody.velocity.magnitude does not represent the value of the added torque, but the added force. So how can I get the torque value, like with magnitude?