Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- public class ApplyConstantTorque : MonoBehaviour
- {
- public Rigidbody rigid;
- public Vector3 torquePerSecond;
- public bool localForce = true;
- [Tooltip("If non-zero, we stop applying force after this many seconds")]
- public float stopPushingAfter = 0.0f;
- void Update()
- {
- if (stopPushingAfter >= 0.0f)
- {
- float deltaTime = PhysicsManager.GetDeltaTimeFor(gameObject);
- if (stopPushingAfter > 0.0f)
- {
- stopPushingAfter -= deltaTime;
- 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)
- }
- if (localForce) { rigid.AddRelativeTorque(torquePerSecond * deltaTime); }
- else { rigid.AddTorque(torquePerSecond * deltaTime); }
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment