Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- void OnCollisionEnter(Collision other)
- {
- if (other.gameObject.CompareTag("Player") || other.gameObject.CompareTag("Guest"))
- {
- if (!isPushed)
- {
- transform.rotation = Quaternion.LookRotation(other.transform.position);
- anim.SetBool("isPushed", true);
- Vector3 pushDirection = (other.transform.position - transform.position).normalized;
- guestRgbd.AddForce(pushDirection * pushForce, ForceMode.Impulse);
- StartCoroutine(WaitAndBack());
- }
- }
- }
- IEnumerator WaitAndBack()
- {
- isPushed = true;
- float timeElapsed = 0f;
- yield return new WaitForSeconds(guestWaitTime);
- pushedPosition = transform.position;
- while (timeElapsed < guestWaitTime)
- {
- anim.SetBool("isPushed", false);
- anim.SetBool("isReturning", true);
- transform.position = Vector3.Lerp(pushedPosition, ownPosition, timeElapsed / guestWaitTime);
- timeElapsed += Time.deltaTime;
- yield return null;
- }
- guestRgbd.velocity = Vector3.zero;
- guestRgbd.angularVelocity = Vector3.zero;
- transform.position = ownPosition;
- transform.rotation = Quaternion.LookRotation(groupCenterPosition);
- anim.SetBool("isReturning", false);
- isPushed = false;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement