forked from amanirmk/AMISTAD-intention-exp1
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathhelpUnity.py
More file actions
53 lines (46 loc) · 1.76 KB
/
helpUnity.py
File metadata and controls
53 lines (46 loc) · 1.76 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
52
53
import helpScript as hsc
import magicVariables as mv
import algorithms as alg
import math as m
def drawLine(lineID, line):
lineID = "line" + str(lineID)
length = alg.calcDistance(line.startPos, line.endPos)
yaw = m.radians(alg.calcAngleTo(line.startPos, line.endPos))
hsc.write(lineID + " = Instantiate(line," + hsc.vf(line.startPos) + "," + hsc.qf(yaw) + ");")
hsc.write(lineID + ".transform.localScale = " + hsc.vf([0,length,0]) + ";")
def destroyLine(lineID):
lineID = "line" + str(lineID)
hsc.write("Destroy(" + lineID + ");")
def unitySpawn(objID, prefab, pos, yaw, scale=1):
"""creates a GameObject in unity from the prefab at the indicated pos and rot
input:
script: list of lists
objID: int
prefab: string
pos: vector (list)
rot: quaternion (tuple)
scale: int, defaulted to 1
"""
if prefab == "wall":
scaling = [mv.WALL_WIDTH, scale, mv.WALL_HEIGHT]
else:
scaling = [scale, scale, scale]
hsc.write(hsc.makeID(objID) + " = Instantiate(" + prefab + "," + hsc.vf(pos) + "," + hsc.qf(yaw) + ");")
hsc.write(hsc.makeID(objID) + ".transform.localScale = " + hsc.vf(scaling) + ";")
if objID > hsc.maxID[0]:
hsc.maxID[0] = objID
def unityDestroy(objID):
"""destroys a gameobject in unity
input:
objID: int
"""
hsc.write("Destroy(" + hsc.makeID(objID) + ");")
def unityUpdateObj(objID, objPos, objYaw):
"""updates the position and rotation of an object in unity
input:
objID: int
objPos: vector (list)
objRot: quaternion (tuple)
"""
hsc.write(hsc.makeID(objID) + ".transform.position = " + hsc.vf(objPos) + ";")
hsc.write(hsc.makeID(objID) + ".transform.rotation = " + hsc.qf(objYaw) + ";")