-
Notifications
You must be signed in to change notification settings - Fork 1
/
die.gd
51 lines (42 loc) · 1.38 KB
/
die.gd
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
extends RigidBody
var maxTorque = 200
var maxForce = 200
var stillRolling = true
signal finished(num)
var can_read = false
func _ready():
randomize()
rotation = Vector3(randf() * PI * 2, randf() * PI * 2, randf() * PI * 2)
add_torque(Vector3(randi()%maxTorque - maxTorque/2, randi()%maxTorque - maxTorque/2, randi()%maxTorque - maxTorque/2))
add_central_force(Vector3(randi()%maxForce - maxForce/2, randi()%maxForce - maxForce/2, randi()%maxForce - maxForce/2))
yield(get_tree().create_timer(0.5), "timeout")
can_read = true
func _process(delta):
if stillRolling == true and can_read:
if linear_velocity.length() <= 0.1 && angular_velocity.length() <= 0.1:
stillRolling = false
print_debug(currentlyUp())
emit_signal("finished", currentlyUp())
#x = 6
#y = 2
#z = 4
func currentlyUp():
var basis = transform.basis
var bestNum = 6
var bestAngle = basis.x.angle_to(Vector3.UP)
if ((-basis.x).angle_to(Vector3.UP) < bestAngle):
bestAngle = (-basis.x).angle_to(Vector3.UP)
bestNum = 1
if (basis.y.angle_to(Vector3.UP) < bestAngle):
basis.y.angle_to(Vector3.UP)
bestNum = 2
if ((-basis.y).angle_to(Vector3.UP) < bestAngle):
(-basis.y).angle_to(Vector3.UP)
bestNum = 5
if (basis.z.angle_to(Vector3.UP) < bestAngle):
basis.z.angle_to(Vector3.UP)
bestNum = 4
if ((-basis.z).angle_to(Vector3.UP) < bestAngle):
(-basis.z).angle_to(Vector3.UP)
bestNum = 3
return bestNum