-
Notifications
You must be signed in to change notification settings - Fork 0
/
Grabbing.cs
49 lines (43 loc) · 1.36 KB
/
Grabbing.cs
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
public class Grabbing : MonoBehaviour
{
private Vector3 prev;
private Collider item;
// Start is called before the first frame update
void Start()
{
prev = this.transform.position;
}
// Update is called once per frame
void Update()
{
if (item)
{
if (item.transform.parent == null)
{
item = null;
}
else if (OVRInput.Get(OVRInput.RawAxis1D.Any) == 0)
{
Vector3 velocity = (this.transform.position - prev) / Time.deltaTime;
item.GetComponent<Rigidbody>().isKinematic = false;
item.attachedRigidbody.velocity = velocity * 2;
item.transform.parent = null;
item = null;
}
}
prev = this.transform.position;
}
private void OnTriggerEnter(Collider other)
{
if (OVRInput.Get(OVRInput.Axis1D.Any) > 0 && item == null && (other.CompareTag("grabbable") || other.CompareTag("sliceable")))
{
item = other;
item.transform.parent = this.transform;
//offset = item.transform.position - this.transform.position;
item.attachedRigidbody.isKinematic = true;
}
}
}