Thanks Russ. I’ve tried to implement your suggestion, but I just don’t have the knowledge or experience to make it work properly. This is what I’ve done (don’t laugh, I really tried my best ):
def getPosition(self, mousepos):
self.pickerRay.setFromLens(base.camNode, mousepos.getX(),mousepos.getY())
self.picker.traverse(render)
if self.queue.getNumEntries() > 0:
self.queue.sortEntries()
# This is the clicked position.
self.position = self.queue.getEntry(0).getSurfacePoint(self.environ)
return None
def moveToPosition(self):
# Get the clicked position
self.getPosition(base.mouseWatcherNode.getMouse())
# This is the "start" position
sPos = self.player.getPos()
diff = sPos - self.position # Start position - the clicked position.
if diff > 180:
# if the difference is greater that 180 it's shorter to go the other way
return sPos - (diff - 360)
elif diff < -180:
# or perhaps the OTHER other way...
return sPos - (360 + diff)
else:
# otherwise just go to the original destination
return self.position
playerTurn = self.player.hprInterval(.5,self.position)
playerTurn.start()
p = Picker()
run()
Sadly, this code doesn’t work. But it looks very similar to the code I’m using to MOVE the player to the clicked position (this particular piece of code works nicely):
def getPosition(self, mousepos):
self.pickerRay.setFromLens(base.camNode, mousepos.getX(),mousepos.getY())
self.picker.traverse(render)
if self.queue.getNumEntries() > 0:
self.queue.sortEntries()
self.position = self.queue.getEntry(0).getSurfacePoint(self.environ)
return None
def moveToPosition(self):
# Get the clicked position
self.getPosition(base.mouseWatcherNode.getMouse())
# This is the "start" position
sPos = self.player.getPos()
# Calculate the distance between the start and finish positions.
# This is then used to calculate the duration it should take to
# travel to the new coordinates based on self.movementSpeed
if sPos[0] > self.position[0]:
distanceX = sPos[0] - self.position[0]
else:
distanceX = self.position[0] - sPos[0]
if sPos[1] > self.position[1]:
distanceY = sPos[1] - self.position[1]
else:
distanceY = self.position[1] - sPos[1]
distance = sqrt((distanceX * distanceX) + (distanceY * distanceY))
playerMove = self.player.posInterval((distance / self.movementSpeed), self.position, startPos = sPos)
playerMove.start()
If I can get this code to work without the need for a dummy node, that’d be great, because I already have a camera_dummy_node attached to the player (so that I can rotate the camera around him).
Sorry to be such a pest. Can you see what I’ve done wrong?
Thanks very much.