2021년 4학년 1학기 기업연계프로젝트2 컴퓨터소프트웨어공학과 <원광투어팀> 팀장 : 송유진 팀원 : 김나영, 이경희, 한유진
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

59 lines
1.7 KiB

5 years ago
  1. using System.Collections;
  2. using System.Collections.Generic;
  3. using UnityEngine;
  4. namespace Valve.VR.InteractionSystem.Sample
  5. {
  6. public class LockToPoint : MonoBehaviour
  7. {
  8. public Transform snapTo;
  9. private Rigidbody body;
  10. public float snapTime = 2;
  11. private float dropTimer;
  12. private Interactable interactable;
  13. private void Start()
  14. {
  15. interactable = GetComponent<Interactable>();
  16. body = GetComponent<Rigidbody>();
  17. }
  18. private void FixedUpdate()
  19. {
  20. bool used = false;
  21. if (interactable != null)
  22. used = interactable.attachedToHand;
  23. if (used)
  24. {
  25. body.isKinematic = false;
  26. dropTimer = -1;
  27. }
  28. else
  29. {
  30. dropTimer += Time.deltaTime / (snapTime / 2);
  31. body.isKinematic = dropTimer > 1;
  32. if (dropTimer > 1)
  33. {
  34. //transform.parent = snapTo;
  35. transform.position = snapTo.position;
  36. transform.rotation = snapTo.rotation;
  37. }
  38. else
  39. {
  40. float t = Mathf.Pow(35, dropTimer);
  41. body.velocity = Vector3.Lerp(body.velocity, Vector3.zero, Time.fixedDeltaTime * 4);
  42. if (body.useGravity)
  43. body.AddForce(-Physics.gravity);
  44. transform.position = Vector3.Lerp(transform.position, snapTo.position, Time.fixedDeltaTime * t * 3);
  45. transform.rotation = Quaternion.Slerp(transform.rotation, snapTo.rotation, Time.fixedDeltaTime * t * 2);
  46. }
  47. }
  48. }
  49. }
  50. }