Hello,
I’m trying to develop a side scrolling shooter and, at the moment, I’m struggling with joint manipulation:
I wrote this code fragment in order to have the actor’s shoulder to face the nearPoint:
sh = self.controlJoint(None,'modelRoot','mixamorig:LeftShoulder')
self.pickerRay = CollisionRay()
mpos = self.base.mouseWatcherNode.getMouse()
self.pickerRay.setFromLens(self.base.camNode,mpos.getX(),mpos.getY())
nearPoint = render.getRelativePoint(camera,self.pickerRay.getOrigin())
sh.lookAt(nearPoint)
#RESULT: the joint moves but in the wrong directions
as far as you know, is there any post/open-source game/other which treats a similar issue?
Hmm… It may be that the underlying bone is treating the orientation of the node produced by “controlJoint” as being a relative value–i.e., not an orientation in world-space, but an orientation in the space of the bone’s parent.
It might be worth trying to use “exposeJoint” to get a handle on that parent-node (I’m not sure of whether said joint should be exposed in local space or world space, offhand), and to thus get the position of “nearPoint” relative to the parent-node and use that as the target for “lookAt”.
Hi, thanks for your help. I’m not sure if I get what you’re saying.
I’ve updated the code as follows but it doesn’t work(I’m sure I’m missing something):
sh = self.controlJoint(None,'modelRoot','mixamorig:LeftShoulder')
sh_parent = self.exposeJoint(None,'modelRoot','mixamorig:Spine2')#CHECKED ON BLENDER
self.pickerRay = CollisionRay()
mpos = self.base.mouseWatcherNode.getMouse()
self.pickerRay.setFromLens(self.base.camNode,mpos.getX(),mpos.getY())
nearPoint = render.getRelativePoint(camera,self.pickerRay.getOrigin())
nearVec = render.getRelativeVector(camera, self.pickerRay.getDirection())
#I've tried to compute nearPoint relatively to sh_parent by creating
#a new node whose position is nearPoint and then I called x's getPos
#passing sh_parent as the 'other' parameter(from the docs: "Returns the
#relative position of the referenced node as seen from the other node."
x = self.base.render.attachNewNode('np')
x.setPos(nearPoint)
nearPoint_rel = x.getPos(sh_parent)
sh.lookAt(nearPoint_rel)
That looks like what I had in mind. The one additional thought that I had towards it was to have the parent-joint be exposed in local space–this can be done by passing the parameter “localTransform = True” to the call to “exposeJoint”. Like so:
jointNodePath = actorObject.exposeJoint(None, "modelRoot", jointName, localTransform = True)
[edit]
Of course, it occurs to me that it might be worth checking that your target-point is ending up where you intend it to. You could perhaps place an object halfway between the “near-point” and the “far-point” (so that it’s within view, rather than being located at the camera’s near-plane) and see whether you have your object looking at the point that you expect.
Yes, you’re right! I’ve tried to do as you said(I had the joint looking at an object) and it worked.
That is, I’m unable to calculate the required point starting from mouse position…
Considering that my camera is updated by a task as follows:
camera.sePos(3,self.player.getPos().y,self.player.getPos().z + 0.5)
camera.lookAt(self.player)
is there any procedure which allows me to pick a point on the Y-Z plan?
1 Like
Aaah, yeah, sometimes it’s wise to check that our inputs are as expected! ^^;
There is a convenience function/technique that allows one to pick a point on a plane–in your case you would simply set up the plane to align with the Y-Z plane. See here:
https://discourse.panda3d.org/t/super-fast-mouse-ray-collisions-with-ground-plane/
(It references a “ground plane”, but it should work for any arbitrary plane, I believe.)
1 Like
Yes, It works! Thank you very much for your support 
1 Like
Excellent, and it’s my pleasure, respectively! 