-
Notifications
You must be signed in to change notification settings - Fork 1
/
PenisGrabber.cs
178 lines (150 loc) · 5.49 KB
/
PenisGrabber.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
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
using UnityEngine;
public class PenisGrabber : MonoBehaviour
{
[SerializeField]
private PenisManager manager;
[SerializeField]
private LayerMask mask;
[SerializeField]
private int penisLayer;
[SerializeField]
private float moveSpeed;
[SerializeField]
private float zMoveSpeed;
[SerializeField]
private float zMax;
[SerializeField]
private float zMin;
[SerializeField]
private float zMoveRate;
[SerializeField]
private float xClamp;
[SerializeField]
private float yMin;
[SerializeField]
private float yMax;
[SerializeField]
private LayerMask zMask;
[SerializeField]
private float grabbedMass;
[SerializeField]
private float massScale;
[SerializeField]
private float heightMultiplyer;
[SerializeField]
private float heightClamp;
[SerializeField]
private float connectedMassScale;
[HideInInspector]
public bool isGrabbing = false;
FixedJoint joint;
HingeJoint itemJoint;
float ogMass;
Rigidbody currentRigidbody;
bool wereTwo = false;
Vector3 lastPoint = Vector3.zero;
bool isPenis = false;
float ogZMoveSpeed;
Item item;
private void Start()
{
ogZMoveSpeed = zMoveSpeed;
}
// Update is called once per frame
void Update()
{
if (Input.GetMouseButton(0)) // Input.touchCount > 0
{
//Touch touch = Input.GetTouch(0);
Ray ray = Camera.main.ScreenPointToRay(Input.mousePosition); // touch.position
Physics.Raycast(ray, out RaycastHit hit, Mathf.Infinity, mask);
float height = Mathf.Clamp(Input.mousePosition.y * heightMultiplyer, 0f, heightClamp); // touch.position.y
if (hit.transform.gameObject != gameObject && !isGrabbing)
transform.position = hit.point;
if (hit.transform.gameObject != gameObject && isGrabbing && isPenis)
transform.position = new Vector3(Mathf.Clamp(hit.point.x, -xClamp, xClamp), Mathf.Clamp(hit.point.y, yMin, yMax) * heightMultiplyer, transform.position.z); // y: height
else if(hit.transform.gameObject != gameObject && isGrabbing)
transform.position = new Vector3(hit.point.x, hit.point.y * heightMultiplyer, transform.position.z); // y: height
if (item != null && itemJoint != null && item.axis)
itemJoint.axis = item.sideAxis;
}
else // Input.touchCount == 0
{
LetGo();
}
if (Input.GetMouseButton(1) && isGrabbing) // Input.touchCount > 1
{
//Touch touch = Input.GetTouch(1);
wereTwo = true;
Ray ray = Camera.main.ScreenPointToRay(Input.mousePosition); // touch.position
Physics.Raycast(ray, out RaycastHit hit, Mathf.Infinity, zMask);
float delta = (hit.point - lastPoint).normalized.z;
delta = delta < 0 ? -1f : delta > 0 ? 1f : 0f;
if (transform.position.z >= zMax)
delta = -1f;
else if (transform.position.z <= zMin)
delta = 1f;
lastPoint = hit.point;
if (hit.transform.gameObject != gameObject)
transform.position = Vector3.Lerp(transform.position, transform.position + new Vector3(0f, 0f, delta * zMoveRate), zMoveSpeed * Time.deltaTime);
if (item != null && itemJoint != null && item.axis)
itemJoint.axis = item.forwardAxis;
}
/*
if (wereTwo && Input.touchCount == 1 && isPenis)
{
LetGo();
wereTwo = false;
}
*/
}
private void OnTriggerEnter(Collider other)
{
if((other.CompareTag("Grababble") || other.CompareTag("PenisPoint")) && other.GetComponent<Rigidbody>() && !isGrabbing)
{
if(other.gameObject.layer == penisLayer)
{
isPenis = true;
joint = gameObject.AddComponent<FixedJoint>();
joint.connectedBody = other.GetComponent<Rigidbody>();
joint.massScale = massScale;
joint.connectedMassScale = connectedMassScale;
currentRigidbody = other.GetComponent<Rigidbody>();
currentRigidbody.useGravity = false;
ogMass = currentRigidbody.mass;
currentRigidbody.mass = grabbedMass;
manager.hardness += 1f;
isGrabbing = true;
}
else if(other.GetComponent<Item>())
{
item = other.GetComponent<Item>();
itemJoint = item.SetUp(GetComponent<Rigidbody>());
isGrabbing = true;
isPenis = false;
zMoveSpeed = item.zMoveSpeed;
}
}
}
void LetGo()
{
if (currentRigidbody != null)
{
currentRigidbody.useGravity = true;
currentRigidbody.mass = ogMass;
}
zMoveSpeed = ogZMoveSpeed;
isGrabbing = false;
if (itemJoint != null)
{
//item.ToggleAbilityButton();
Rigidbody rb = itemJoint.GetComponent<Rigidbody>();
Destroy(itemJoint);
//Update Physics
rb.useGravity = false;
rb.useGravity = true;
}
if (joint != null)
Destroy(joint);
}
}