So this problem is driving me crazy! I tried almost everything from changing rotations in Blender to doing local/global rotations with/without flattening. Nothing seems to help. Basically I figured out that my model’s joint seems to have its axes swapped (although the texture is applied correctly). The problem is that I’m parenting my camera to that joint and when I attempt to rotate my joint around the Heading (setH), my camera is rotating correctly, but my model’s joint is actually rotating around the Roll! Of course I could just change the Roll of my model (setR) which in reality is its heading but then, of course, my camera would rotate around the Roll as well which I don’t want.
So why has my joint these two things interchanged and more importantly how can I fix that, preferably in Panda3d and not in Blender?
player = Actor(loader.loadModel("resources/obj/player.bam"))
player.custom_skin_texture = loader.load_texture("skins/man.png")
player.custom_texture_stage = TextureStage("stage0")
player.set_texture(player.custom_texture_stage, player.custom_skin_texture, 1)
self.neck = player.controlJoint(None, "modelRoot", "Neck1")
camera._cam.reparentTo(self.neck) # This is the base.camera
camera._cam.setPos(0, -4, 0) # So that I can see my player's head movement
self.neck.setH(self.roty) # Camera behavior correct, player behavior like setR
And in case it helps for finding the issue, here’s the egg file I converted from my BAM file which in turn I created from my blend file: https://filebin.ca/5O6VTxFgL9RK
I’d be very grateful about your suggestions.
It might help to point out which exporter you used. Did you use blend2bam?
Ah, yes, I used blend2bam with Blender 2.80
Have you checked the relevant bone’s axes in Blender? Perhaps they’re not oriented as expected. (Something that I think that I’ve found before!)
Otherwise, I might hazard a guess based on your description: I see that you’re attaching your camera to a “neck”-joint. If the bone in question is thus oriented upwards, then its y-axis might be oriented upwards. This would mean that a turning of the head would be a rotation around that y-axis, and thus in Panda terms a change of the “roll”, not the “heading”.
Oh, that’s indeed a point. The whole character is standing upwards and not lying on the ground. But I don’t know if that’s a reason. I tried to rotate the head in Blender but didn’t notice any change in Panda3D. Could you, if you had the time, take a brief look at my .blend file? It’s a rather simple one!
I could try, but I’m afraid that I use Blender 2.78, not 2.8, and I doubt that the file would be compatible…
When you say that you “tried to rotate the head in Blender”, what do you mean? Did you pose the bone that controls the head-vertices of the model? Did you change the model itself? Did you change the armature such that the relevant bone pointed in another direction? Something else again?
So I tried to rotate it by selecting the Mesh, switching to edit mode and changing the X rotation by 90%. I’m not sure if this is even right.
And I actually just imported the following fbx file I got from Kenney.nl
to get a Blend file I could convert to bam (I had to scale this up by 42 if I recall correctly) basicCharacter.zip (15.0 KB)
The mesh, not the armature? If so, then this wouldn’t affect how the joints rotate, I believe; it should just change the base appearance of the model itself.
Looking at the FBX file that you posted, it looks like the neck-joint is indeed oriented such that its y-axis points upwards. Thus a turn of the head to the left or right is indeed a rotation of the joint’s “R”-angle, not its “H”-angle, I believe.
If you want such a turn of the head to be associated with setting the joint’s “H”-angle, then editing the armature such that the neck-bone points “forwards” should do the job. (For the sake of clarity, let me note that I’m not talking about posing the neck-bone in Blender, but rather about editing it.)
Be aware, however, that this may have implications for any animations that you may have. Also perhaps take note of which way the bone considers to be “up” after rotation, and perhaps correct that if called for, as that might affect how rotation of the “P”-angle might apply.
Thank you for looking into it! I tried what you suggested but unfortunately this just makes my camera be rotated by 90 degrees around its “R”-angle. I can still see that my player’s head has the same wrong axes as before unfortunately. Below is a screenshot of my Blender screen:
and this is a screenshot of the game:
Although he looks friendly, I prefer if his head were straight up and instead turned around the up axis.
Well, you would have to adjust your camera’s code to account for the change, I daresay: what was correct with the previous configuration will likely be incorrect with the new one.
That’s odd–just to check: have you changed your code to rotate the “H”-angle rather than the “R”-angle after editing and exporting the updated armature?
About the camera code… I see. I’ll correct that once the player is behaving correctly then.
And my code did in fact already rotate around the “H”-angle:
since I preferred correct camera movement over correct player’s head movement. But a good idea - sometimes really dumb things are the cause for weird situations. But in this case, I think something else is wrong.