-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathSimpleExtraction.cs
More file actions
51 lines (43 loc) · 1.39 KB
/
Copy pathSimpleExtraction.cs
File metadata and controls
51 lines (43 loc) · 1.39 KB
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
using UnityEngine;
public class SimpleExtraction : MonoBehaviour
{
private Vector3 initialPosition;
public float pullDistanceNeeded = 0.005f;
private bool isExtracted = false;
private Rigidbody rb;
private Vector3 lastPosition;
private float velocityThreshold = 0.1f;
void Start()
{
initialPosition = transform.position;
lastPosition = transform.position;
rb = GetComponent<Rigidbody>();
if (rb != null)
{
rb.isKinematic = true;
}
}
void Update()
{
if (isExtracted || rb == null) return;
// احسب المسافة من المكان الأصلي
float distance = Vector3.Distance(transform.position, initialPosition);
// احسب السرعة
float velocity = Vector3.Distance(transform.position, lastPosition) / Time.deltaTime;
lastPosition = transform.position;
Debug.Log($"Distance: {distance}, Velocity: {velocity}");
// إذا اتحرك السن بسرعة كافية أو مسافة كافية = تخلع
if (distance >= pullDistanceNeeded || velocity > velocityThreshold)
{
ExtractTooth();
}
}
void ExtractTooth()
{
isExtracted = true;
transform.SetParent(null);
rb.isKinematic = false;
rb.useGravity = true;
Debug.Log("Tooth Extracted!");
}
}