Guest User

Untitled

a guest
Feb 1st, 2018
34
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.78 KB | None | 0 0
  1. public class ApplyConstantTorque : MonoBehaviour
  2. {
  3. public Rigidbody rigid;
  4. public Vector3 torquePerSecond;
  5. public bool localForce = true;
  6.  
  7. [Tooltip("If non-zero, we stop applying force after this many seconds")]
  8. public float stopPushingAfter = 0.0f;
  9.  
  10. void Update()
  11. {
  12. if (stopPushingAfter >= 0.0f)
  13. {
  14. float deltaTime = PhysicsManager.GetDeltaTimeFor(gameObject);
  15. if (stopPushingAfter > 0.0f)
  16. {
  17. stopPushingAfter -= deltaTime;
  18. if (stopPushingAfter <= 0.0f) { stopPushingAfter = -1.0f; } // (if we started with a decay param, make sure we finish under 0.0 so we actually STOP)
  19. }
  20.  
  21. if (localForce) { rigid.AddRelativeTorque(torquePerSecond * deltaTime); }
  22. else { rigid.AddTorque(torquePerSecond * deltaTime); }
  23. }
  24. }
  25. }
Advertisement
Add Comment
Please, Sign In to add comment