using System.Collections;
using System.Collections.Generic;
using UnityEngine;
public class LeafPhysics : MonoBehaviour {
private Rigidbody body;
// Use this for initialization
void Start () {
body = GetComponentInChildren<Rigidbody>();
}
public float TorqueForceUpScale = 0.3f;
public float TorqueScale = 1.0f;
public float TorqueBounds = 5.0f;
// Update is called once per frame
void Update () {
float torqueX = -transform.up.x;
float torqueZ = -transform.up.z;
float forceUp = Mathf.Abs(torqueX) * TorqueForceUpScale + Mathf.Abs(torqueZ) * TorqueForceUpScale;
body.AddRelativeForce(Vector3.up * forceUp);
body.AddRelativeTorque(new Vector3(Mathf.Max(-TorqueBounds, Mathf.Min(TorqueBounds, torqueX * TorqueScale)), 0, Mathf.Max(-TorqueBounds, Mathf.Min(TorqueBounds, torqueZ * TorqueScale))));
}
}