BoneLookController and Bone orientation

I’m using BoneLookController to rotate bones in YBot skeleton (dummy3.babylon),
but I’m having issues with bones “flipping” orientation on their own depending on small changes in target Vector.

For example, see attached image - same everything only X coordinate of target vector is different by few pixels and bone orientation flipped (facing back in first image and facing front in second image).


I can control the flip by having complex “adjust” rules like this:

    this.person.lookControllers.LeftUpLeg.adjustPitch = flipLeftLeg ? -Math.PI / 2 : +Math.PI / 2;
    this.person.lookControllers.LeftUpLeg.adjustRoll = flipLeftLeg ? 0 : Math.PI;

but I’d really want to avoid that - any thoughts/ideas?

Let me ping @adam who create that controller for BJS

It sounds like you might need to play around with the upAxis option.

Also, what version of BJS are you using?

It appears that the BoneLookController isn’t performing correctly in BJS 5.

1 Like

I’ve tried BabylonJS 4.2.1 and 5.0.0.beta4 and behavior seems the same to me
I have no issues with BoneLookController other than this strange bone “flip”

A bit more details - seems like flip happens when delta of bone position vs target vectors switches between positive to negative, even if its a trivial change like from -0.001 to +0.001.

I’ll try playing with upAxis

Still not 100% sure how upAxis works internally and what are correct ranges, but I’m now getting decent results with this:

    const facingForward = Math.sign(kpts[SMPLKeypoints.leftHip][0] - kpts[SMPLKeypoints.rightHip][0]);
    lookControllers.LeftUpLeg.upAxis = new Vector3(-facingForward / 2, 1, -facingForward);
    lookControllers.LeftLeg.upAxis = new Vector3(-facingForward / 2, 1, -facingForward);
    lookControllers.RightUpLeg.upAxis = new Vector3(+facingForward / 2, 1, -facingForward);
    lookControllers.RightLeg.upAxis = new Vector3(+facingForward / 2, 1, -facingForward);

any chance you might ramp-up docs for upAxis?
right now there is nothing there:

Sometimes the docs are hard to find because of the very nested structure

Also, if you hit the “.” Button on your keyboard in the babylon github repo , it’ll open a web version of vscode that you can search the source code.

@jeremy-coleman there is not a word there about upAxis, its only visible in API docs and even there it’s just listed as existing (and that is auto-generated from TypeDocs, which means it’s not even documented in the code). Nothing else. Ask is to document it.

I did look at the code. And that didn’t really help :frowning_face:
(I’d need to digest entire logic of BoneLookController to make sense of it)

  • Default is Vector3.Up() which is [0, 1, 0]
  • Its sometimes normalized: upAxis.normalize()
  • Its used by many ops: Vector3.TransformCoordinatesToRef, Bone.getDirectionToRef, Vector3.Cross, Matrix.FromXYZAxesToRef (and others)

Ah, just sharing what i know. Maybe helpful, maybe useless. Anyway here is a pg search. Searching the playgrounds for the class name im having trouble with is something i do frequently.

.Playground search page | Babylon.js Documentation

The docs on the look controller say its from v2.5 which was forever ago. A lot of the classes accept a handedness argument. Maybe upAxis is direction of your thumb in the way a lot of people think about

Or yaw pitch roll


Maybe the switch is expected. The docs say “The BoneLookController class is used to make a bone look toward a point in space.” If x’s sign changes that should maybe be expected to cause a flip in look direction? Sorry im likely not much help here

maybe. but then again, i’m getting slight difference when using 0.5 vs 1 as value, so its not just a switch.
thus my ask for devs to document it :slight_smile:

1 Like

If I remember correctly, up axis is to help set the roll of the bone. If the bone is rolling around or flipping, then it’s likely that your bone is looking close to the direction of the up axis.

It could also be looking close to the opposite direction of the up axis.

@adam based on my observations, flipping occurs when bone is looking close to the opposite direction of upAxis. if upAxis is set correctly, then flipping does not occur.

But default value of [0, 1, 0] is ok only for bones belonging to center of the body.
For bones that are either left or right, better defaults are [-1, 1, 1] for left-handed bones and [1, 1, 1] for right-handed bones.

And then flip x and z if body is facing backwards.

(all of this is purely experimental)

1 Like

You might also want to experiment with setting the upAxisSpace to Space.BONE.

The upAxisSpace defaults to Space.LOCAL which is the local space of the mesh.


@Cedric would be great if you could check why it is not working in 5.0 ??? Babylon.js Playground this looked all good in 4.2 :frowning:

Sure! I’m on it!

1 Like



Dunno how you found it but you ROCK !!!


Hi @vladmandic just checking in, do you still have any questions? :slight_smile:

@carolhmj plenty of questions in general as i’m still learning babylon, but this topic is clear - i’m seriously amazed by level of help provided here! my bad that i haven’t selected a solution, done now.


No probs! Anything else you wanna ask, the forum will be more than happy to help! :smiley: