PathEntity.py 2.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657
  1. from toontown.toonbase.ToontownGlobals import *
  2. from direct.interval.IntervalGlobal import *
  3. from direct.directnotify import DirectNotifyGlobal
  4. import BasicEntities
  5. from toontown.suit import GoonPathData
  6. class PathEntity(BasicEntities.NodePathEntity):
  7. def __init__(self, level, entId):
  8. BasicEntities.NodePathEntity.__init__(self, level, entId)
  9. self.path = GoonPathData.Paths[self.level.factoryId][self.pathIndex]
  10. def destroy(self):
  11. BasicEntities.NodePathEntity.destroy(self)
  12. def setPathIndex(self, pathIndex):
  13. self.pathIndex = pathIndex
  14. self.path = GoonPathData.Paths[self.level.factoryId][self.pathIndex]
  15. def makePathTrack(self, node, velocity, name, turnTime=1, lookAroundNode=None):
  16. track = Sequence(name = name)
  17. assert (len(self.path) > 1)
  18. # end with the starting point at the end, so we have a continuous loop
  19. path = self.path + [self.path[0]]
  20. for pointIndex in range(len(path) - 1):
  21. startPoint = path[pointIndex]
  22. endPoint = path[pointIndex + 1]
  23. # Face the endpoint
  24. v = startPoint - endPoint
  25. # figure out the angle we have to turn to look at the next point
  26. # Note: this will only look right for paths that are defined in a
  27. # counterclockwise order. Otherwise the goon will always turn the
  28. # "long" way to look at the next point
  29. node.setPos(startPoint[0], startPoint[1],startPoint[2])
  30. node.headsUp(endPoint[0], endPoint[1], endPoint[2])
  31. theta = node.getH() % 360
  32. track.append(
  33. LerpHprInterval(node, # stop and look around
  34. turnTime,
  35. Vec3(theta,0,0)))
  36. # Calculate the amount of time we should spend walking
  37. distance = Vec3(v).length()
  38. duration = distance / velocity
  39. # Walk to the end point
  40. track.append(
  41. LerpPosInterval(node, duration=duration,
  42. pos=Point3(endPoint),
  43. startPos=Point3(startPoint)))
  44. return track