I’m working on a Minecraft clone and I want the CollisionCapsule of the player just follow the heading of the camera not the pitch. Could someone help me? I already tried using self.playerPathNode.setHpr(self.camera, Vec3(self.camera, 0, 0)) at the setupCamera function and the update one but it dosen’t work.
You can update only the necessary rotation components.
self.playerPathNode.setH(self.camera.getH())
self.playerPathNode.setP(self.camera.getP())
I’d recommend representing the player with a hierarchy of two nodes: A base-node that controls heading (and position), and as a child of that node, a second node that controls (only) pitch.
As the pitch-node would be a child of the heading-node, it would naturally turn with the heading-node, as well as pitching by itself. If the camera were to then be attached to the pitch-node, it would thus turn and pitch with that node, as one might expect.
But as the heading-node doesn’t itself pitch, you can then attach your player-collider to the heading node and have it move and turn with the player, but not pitch!
Something like this:
# Position and heading
self.mainNode = NodePath(PandaNode("main node")
# Pitch
self.pitchNode = self.mainNode.attachNewNode(PandaNode("pitch node"))
self.collider.reparentTo(self.mainNode)
self.camera.reparentTo(self.pitchNode)
### Later in your code...
# To position the player:
self.mainNode.setPos(newPos)
# To turn the player:
self.mainNode.setH(newH)
# To pitch the player (and the camera with them):
self.pitchNode.setP(newP)
1 Like