I want my player’s head to look at the mouse cursor, like in Super Mario 64.
“Looking and Gripping” sample has an example for that, but it seems to be a hardcoded values which just happen to make things look kind of correct.
Plus my character is moving in 3d space with the camera.
This is my code. Do you need it?
def task(self, task):
self.world.doPhysics(globalClock.getDt(), 10, 1.0/160)
if self.key['mouse']: # Determine whether the mouse is pressed
if base.mouseWatcherNode.hasMouse():
x=base.mouseWatcherNode.getMouseX()
y=base.mouseWatcherNode.getMouseY()
self.playerNP.setH(math.atan2(y,x)*57.29578+90)
return task.again
If you want use the code, you have to keep that camera’s focus on the player always.
Edit:
oh … I forgot it:
self.playerNP.setH(math.atan2(y,x)*57.29578+90+camera.getH())
If the above doesn’t suit your purposes:
You should be able to get the appropriate point using a ray-cast, as shown here.
On the other hand, if your set of potential points is confined to a plane – if, for example, you only want to pick “floor positions” on a perfectly flat floor with no steps or other changes in height – you might find this quicker method more useful.