Jump to content

How to target FollowCamera on child mesh?


kevzettler
 Share

Recommended Posts

I have a complex modular character. The character has a parent (Anchor) mesh and many child meshes. I want to target FollowCamera on one of the child meshes (Head). When I assign Head to  FollowCamera.lockedTarget the behavior is not desired. The camera points at coordinates that match the Anchor element. The camera appears to follow the local position of Head and not the expected world position.

Check this play ground
http://www.babylonjs-playground.com/#ZXP4M#11

Link to comment
Share on other sites

Hello,

Because your head object is tied to bones, it's world position is controlled by bones. So the idea would be to attach a mesh to the bone controlling the head and point your target to this dummy mesh.

Here is a sample of how AttachToBone works: http://www.babylonjs-playground.com/#11BH6Z#154 (see line #54)

 

Link to comment
Share on other sites

@Deltakosh Thanks for the answer. I'm confused though and have a follow-up question.

How would I get relative positions to the bound meshes? I'd want to position the "Dummy" LockedTarget mesh relative to the Head. I will also want to get other positions relative to the hands and such. I don't believe the bones have positions. Are you saying I would have to first attach Dummy Meshes to bones and position relatively from there?

Link to comment
Share on other sites

@Deltakosh i've updated the PG with your suggestion and added:

 

      var targetDummy = BABYLON.Mesh.CreateSphere("root", 16, 1, scene, true);
      var headBone =  skeletons[0].bones[skeletons[0].getBoneIndexByName('Head')];
      var headMesh =  scene.getMeshByName('Head');
      targetDummy.attachToBone(headBone, headMesh);
      var target = targetDummy;


It did not have the expected behavior. See: 

http://www.babylonjs-playground.com/#ZXP4M#15


 

Link to comment
Share on other sites

Hi @Deltakosh Thanks for helping with this. I'd rather you spend your time updating Babylon, much appreciated

Quote

Hello, are you sure of the mesh and bone names?

Do you mean the "Head" mesh and bone? I added log output showing that they are objects
How else can I verify?

var headBone =  skeletons[0].bones[skeletons[0].getBoneIndexByName('Head')];
var headMesh =  scene.getMeshByName('Head');
console.log(headBone);
console.log(headMesh);

 

Quote

Even without talking about the FollowCamera, it seems to me that your mesh is not linked to the bone:

Again which mesh to which bone? The "Dummy" mesh or the "Head" mesh. How do I verify? These meshes and bones are exported straight from Blender. I have not manually attached them in Babylon. I also enabled an animation. The animation would not play if the bones were not linked, correct?

http://www.babylonjs-playground.com/#ZXP4M#18

Link to comment
Share on other sites

 

Thanks @Deltakosh, looks like the mesh is now attached to the bone. Going back to the original question, I have updated the PG to use FollowCamera and target the TargetDummy mesh, see http://www.babylonjs-playground.com/#ZXP4M#23. Unfortunately, it does not actually follow the meshes position. I see in PG#22 there was a condition added to the render loop:

This forces the camera to target on the meshes "absolute position"  each frame. If I log TargetDummy.position and Target.getAbsolutePosition() I see that .position is never updated its always {x: 0, y: 0, z: 0} 

Unfortunately, it looks like FollowCamera internally assumes mesh.position is updated. see:
https://github.com/BabylonJS/Babylon.js/blob/master/src/Cameras/babylon.followCamera.ts#L47-L49

So I don't think this will work without a method of updating the target's position or updating FollowCamera to use getAbsolutePosition()

 

Link to comment
Share on other sites

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.
Note: Your post will require moderator approval before it will be visible.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

Loading...
 Share

  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...