drag rigidbody unity code example
Example 1: how to drag a 2d rigidbody in unity
// add this to your player. Make sure there is a rigidbody2d attached to it. private Vector2 direction; public float force = 1000; private Rigidbody2D r; void Start () { r = transform.GetComponent <Rigidbody2D> (); } void Update { if (Input.touchCount > 0) { target = Camera.main.ScreenToWorldPoint(Input.GetTouch(0).position); direction = (target.transform.position - transform.position).normalized; r.AddForce (direction * Time.deltaTime * force); } }
Example 2: how to change the drag of a rigidbody in unity through script
public Rigidbody rb;
void Start()
{
rb = GetComponent<Rigidbody>();
}
void OpenParachute()
{
rb.drag = 20;
}
void Update()
{
if (Input.GetButton("Space"))
OpenParachute();
}