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.
|
|
using System.Collections;using System.Collections.Generic;using UnityEngine;using Valve.VR;
public class grabInteraction : MonoBehaviour{ public SteamVR_Input_Sources handType; //���� ����, ��, ������
public SteamVR_Behaviour_Pose controllerPose; // ��Ʈ�ѷ� ����
public SteamVR_Action_Boolean grabAction; //�� ��
private GameObject collidingObject; //���� �浹���� ��ü
private GameObject objectInHand; //�÷��̾ ���� ��ü
private void Update() { //trigger ��ư�� ���� ��
if (grabAction.GetLastStateDown(handType)) { if (collidingObject) { GrabObject(); } }
//trigger ��ư�� ���� ��
/* if (grabAction.GetLastStateDown(handType)) { if (objectInHand) { GrabObject(); } }*/ }
// �浹�� ���۵Ǵ� ����
public void OnTriggerEnter(Collider other) { SetCollidingObject(other); } // �浹 ���� ��
public void OnTriggerStay(Collider other) { SetCollidingObject(other); } // �浹�� ������ ����
public void OnTriggerExit(Collider other) { if (!collidingObject) return; collidingObject = null; }
//�浹 ���� ��ü�� ����
private void SetCollidingObject(Collider col) { //�̹� �浹 ���̰ų� rigidbody�� ������ ���� ���� ���� ����ó��
if (collidingObject || !col.GetComponent<Rigidbody>()) return; collidingObject = col.gameObject; }
//��ü ����
private void GrabObject() { objectInHand = collidingObject; //���� ��ü�� ����
collidingObject = null; //�浹 ��ü ����
var joint = AddFixedJoint(); joint.connectedBody = objectInHand.GetComponent<Rigidbody>(); } //FixedJoint=>��ü���� �ϳ��� ���� ����������
//breakForce=>����Ʈ�� ���ŵǵ��� �ϱ� ���� �ʿ��� ���� ũ��
//breakTorque=>����Ʈ�� ���ŵǵ��� �ϱ� ���� �ʿ��� ��ũ
//joint �߰�
private FixedJoint AddFixedJoint() { FixedJoint joint = gameObject.AddComponent<FixedJoint>(); joint.breakForce = 20000; joint.breakTorque = 20000; return joint; } //��ü ����
// controllerPose.GetVelocity()=>��Ʈ�ѷ� �ӵ�
// controllerPose.GetAngularVelocity=>��Ʈ�ѷ� ���ӵ�
/* private void ReleaseObject(){if (GetComponent<FixedJoint>()) {GetComponent<FixedJoint>().connectedBody = null; Destroy(GetComponent<FixedJoint>()); objectInHand.GetComponent<Rigidbody>().velocity= controllerPose.GetVelocity() ; objectInHand.GetComponent<Rigidbody>().angularVelocity = controllerPose.GetAngularVelocity();}objectInHand = null;}*/}
|