Advertisement
LeeMace

Add random upwards force in a range to object

Dec 1st, 2022 (edited)
43
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 0.34 KB | Gaming | 0 0
  1.  private Rigidbody targetRb;
  2.  
  3.  private float minSpeed = 12;
  4.     private float maxSpeed = 16;
  5.  
  6.  void Start()
  7.     {
  8.         targetRb = GetComponent<Rigidbody>();
  9.         targetRb.AddForce(RandomForce(), ForceMode.Impulse);
  10.        
  11.     }
  12.  
  13. Vector3 RandomForce()
  14.     {
  15.         return Vector3.up * Random.Range(minSpeed, maxSpeed);
  16.     }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement