Advertisement
i-Xuup

Duda LookRotation

May 28th, 2024
724
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 1.40 KB | None | 0 0
  1.     void OnCollisionEnter(Collision other)
  2.     {
  3.         if (other.gameObject.CompareTag("Player") || other.gameObject.CompareTag("Guest"))
  4.         {
  5.             if (!isPushed)
  6.             {
  7.                 transform.rotation = Quaternion.LookRotation(other.transform.position);
  8.                 anim.SetBool("isPushed", true);
  9.                 Vector3 pushDirection = (other.transform.position - transform.position).normalized;
  10.                 guestRgbd.AddForce(pushDirection * pushForce, ForceMode.Impulse);
  11.                 StartCoroutine(WaitAndBack());
  12.             }
  13.         }
  14.     }
  15.  
  16.     IEnumerator WaitAndBack()
  17.     {
  18.         isPushed = true;
  19.         float timeElapsed = 0f;
  20.         yield return new WaitForSeconds(guestWaitTime);
  21.         pushedPosition = transform.position;
  22.         while (timeElapsed < guestWaitTime)
  23.         {
  24.             anim.SetBool("isPushed", false);
  25.             anim.SetBool("isReturning", true);
  26.             transform.position = Vector3.Lerp(pushedPosition, ownPosition, timeElapsed / guestWaitTime);
  27.             timeElapsed += Time.deltaTime;
  28.             yield return null;
  29.         }
  30.         guestRgbd.velocity = Vector3.zero;
  31.         guestRgbd.angularVelocity = Vector3.zero;
  32.         transform.position = ownPosition;
  33.         transform.rotation = Quaternion.LookRotation(groupCenterPosition);
  34.         anim.SetBool("isReturning", false);
  35.         isPushed = false;
  36.     }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement