SHARE
TWEET

Untitled

a guest Jun 20th, 2019 59 Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1.         //returns -1 when to the left, 1 to the right, and 0 for forward/backward
  2.     public float AngleDir(Vector3 fwd, Vector3 targetDir, Vector3 up)
  3.     {
  4.         Vector3 perp = Vector3.Cross(fwd, targetDir);
  5.         float dir = Vector3.Dot(perp, up);
  6.  
  7.         if (dir > 0.0f) {
  8.             return 1.0f;
  9.         } else if (dir < 0.0f) {
  10.             return -1.0f;
  11.         } else {
  12.             return 0.0f;
  13.         }
  14.     }  
  15.  
  16.  
  17.  
  18.             RaycastHit hit;
  19.             // Does the ray intersect any objects excluding the player layer
  20.             if(doSteering == true)
  21.             {
  22.                 if (Physics.Raycast(transform.position, transform.TransformDirection(Vector3.forward), out hit, Mathf.Infinity))
  23.                 {
  24.                     Debug.DrawRay(transform.position, transform.TransformDirection(Vector3.forward) * hit.distance, Color.yellow);
  25.                     Debug.Log("Did Hit");
  26.                     float dirHit = AngleDir(transform.forward, hit.transform.position, transform.up);
  27.                     if(dirHit == -1)
  28.                     {
  29.                         rbody.AddRelativeForce(Vector3.left * 50, ForceMode.Acceleration);
  30.                         Debug.LogError("FORCE FROM THE LEFT");
  31.                     }
  32.                     else if(dirHit == 1)
  33.                     {
  34.                         rbody.AddRelativeForce(Vector3.right * 50, ForceMode.Acceleration);
  35.                         Debug.LogError("FORCE FROM THE RIGHT");
  36.                     }
  37.                     else
  38.                     {
  39.                         //front;
  40.                         rbody.AddRelativeForce(Vector3.up*50, ForceMode.Acceleration);
  41.                         Debug.LogError("FORCE IT UP");
  42.                     }
  43.                 }
  44.                 else
  45.                 {
  46.                     Debug.DrawRay(transform.position, transform.TransformDirection(Vector3.forward) * 1000, Color.white);
  47.                 }
  48.             }
RAW Paste Data
We use cookies for various purposes including analytics. By continuing to use Pastebin, you agree to our use of cookies as described in the Cookies Policy. OK, I Understand
Not a member of Pastebin yet?
Sign Up, it unlocks many cool features!
 
Top