Advertisement
ivan866

directions-controls-unitycsharp

Feb 8th, 2022
1,221
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 1.06 KB | None | 0 0
  1. jitter = Random.Range(0.1f, 0.4f);
  2. toCheck = 0.0f;
  3. THRESHOLD = 0.9f;
  4. THRES_DIRECTION = 1;
  5.  
  6. if (direction == 1) {
  7.     direction_vector.x -= jitter;
  8.     toCheck = direction_vector.x;
  9.     THRESHOLD *= -1;
  10.     THRES_DIRECTION = -1;
  11. } else if (direction == 0) {
  12.     direction_vector.y -= jitter;
  13.     toCheck = direction_vector.y;
  14.     THRESHOLD *= -1;
  15.     THRES_DIRECTION = -1;
  16. } else if (direction == 2) {
  17.     direction_vector.z -= jitter;
  18.     toCheck = direction_vector.z;
  19.     THRESHOLD *= -1;
  20.     THRES_DIRECTION = -1;
  21. } else if (direction == 3) {
  22.     direction_vector.x += jitter;
  23.     toCheck = direction_vector.x;
  24. } else if (direction == 4) {
  25.     direction_vector.y += jitter;
  26.     toCheck = direction_vector.y;
  27. } else if (direction == 5) {
  28.     direction_vector.z += jitter;
  29.     toCheck = direction_vector.z;
  30. }
  31.  
  32. switch (THRES_DIRECTION) {
  33.     case -1:
  34.         if (toCheck < THRESHOLD) {
  35.             done = true;
  36.         }
  37.         break;
  38.     case 1:
  39.         if (toCheck > THRESHOLD) {
  40.             done = true;
  41.         }
  42.         break;
  43. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement