本文整理汇总了Python中Map.raycast方法的典型用法代码示例。如果您正苦于以下问题:Python Map.raycast方法的具体用法?Python Map.raycast怎么用?Python Map.raycast使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Map
的用法示例。
在下文中一共展示了Map.raycast方法的1个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: BotClient
# 需要导入模块: import Map [as 别名]
# 或者: from Map import raycast [as 别名]
#.........这里部分代码省略.........
logging.error("findpath failed:")
log.err(deferred.result)
raise Exception, "findpath failed"
path, complete = deferred.result
if path is None:
raise Exception, "findpath failed"
for i, point in enumerate(path):
#This shouldn't fail, as points in the path should be close enough to the player
#But sometimes it does.
try:
if self.map[point] not in walkableBlocks:
found = False
break
except BlockNotLoadedError:
#Find a new path and hope it doesn't happen again
found = False
break
#if we can get to the next block in the path without hitting something,
#skip the current block.
if 0<=i<len(path)-1:
for offset in [
(0, 0, 0),
(-0.5, 0, -0.5), (-0.5, 0, 0.5), (0.5, 0, 0.5), (0.5, 0, -0.5),
(-0.5, 2, -0.5), (-0.5, 2, 0.5), (0.5, 2, 0.5), (0.5, 2, -0.5),]:
if self.map.blockInLine(self.pos+offset, path[i+1]+offset, BLOCKS_UNWALKABLE):
#logging.debug("broke %r" % (offset,))
break
else:
#make sure we don't float for too long
c = 0
for pos in self.map.raycast(self.pos, path[i+1]):
if self.map[pos+(0, -1, 0)] in BLOCKS_WALKABLE:
c += 1
else:
c = 0
if c >= 3:
break
else:
#logging.debug("skip")
continue
for v in self.command_moveTowards(point,
lookTowardsWalk=lookTowardsWalk,
destructive=destructive): yield v
if found and complete:
return
finally:
if setLook:
self.lookTarget = None
def command_moveTowards(self, position, lookTowardsWalk=False, threshold=0.1, speed=None, destructive=False):
if speed is None:
speed = self.speed
while (position - self.pos).mag() > threshold:
dx, dy, dz = position - self.pos
highest = max(map(abs, (dx, dy, dz)))
dmx = (dx/highest)*speed*self.targetTick
dmy = (dy/highest)*speed*self.targetTick
dmz = (dz/highest)*speed*self.targetTick