-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathgoals.py
37 lines (27 loc) · 928 Bytes
/
goals.py
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
from vec import *
import maya.cmds as cmds
class Goals(object):
_goal_index = 0
def getGoals(self):
goals = []
if len(cmds.ls('goal*', r=True)) > 0:
cmds.select('goal*', r=True)
selected = cmds.ls(sl=True)
for item in range(len(selected)/2):
x = cmds.getAttr("%s.translateX" % selected[item])
y = cmds.getAttr("%s.translateY" % selected[item])
z = cmds.getAttr("%s.translateZ" % selected[item])
pos = [x,y,z]
goals.append(pos)
return goals
def calculateGoal(self, currentPosition, goals_array):
goal_index = self._goal_index
if(dist(currentPosition, goals_array[goal_index]) < 5):
goal_index = goal_index + 1
if (goal_index == len(goals_array)):
goal_index = 0
goalVelocity = sub(goals_array[goal_index], currentPosition)
goalVelocity = norm(goalVelocity)
goalVelocity = scale_by_scalar(goalVelocity, 0.7)
self._goal_index = goal_index
return goalVelocity