Godot: Imported Bones dont behave properly with looking_at

Created on 26 Feb 2018  ยท  7Comments  ยท  Source: godotengine/godot

No one seems to be having bone issues, which I assume is becuase no one is toying with this.

125fc8cc4432d28e63da76c3a2aff655b1a7cc6b

Manjaro

Issue description:
Take this script, and use it on some imported arm from blender.

This script intends to make the root bone look at the target affector, but always looks at a tangent to the desired direction.

export(NodePath) var target = null

func _ready():
    $skel/arm.set_surface_material(0,preload("res://skin.tres"))

    var bone_1 = $Skeleton.get_bone_global_pose(0)
    var target_t = $Skeleton.global_transform.affine_inverse() * get_node(target).global_transform
    bone_1.basis = bone_1.looking_at(target_t.origin, bone_1.basis[1]).basis
    $Skeleton.set_bone_global_pose(0, bone_1)

I expect that when using bone_1.basis = bone_1.looking_at(target.origin, bone.basis[1]) that I am only changing the rotation and scale of the bone transform and also pointing it at the target.

Why is it that this makes the arm look at a 90 degree angle??

Does this have to do with the axis swap? Are the bones' forward facing direction accounted for in the GLTF exporter? (escn wouldn't produce a usable result) #17068

Godot should intuitively set the bones' forward direction to -Z. This function doesn't work as expected on bones from blender. I've seen examples online about how to use a script to make bones and that returned positive results when using the looking_at function.

Steps to reproduce:
Use some imported bones and try to move them using looking_at, it will not point in the right direction. This is extremely frustrating as all skeletons will come from blender and this should work as intended, (ie why isn't the fucking bone pointing at the target)

Minimal reproduction project:
ik.zip

EDIT ---

https://blender.stackexchange.com/questions/15609/in-which-direction-should-bone-axes-be-oriented

This answer tells that blender uses Y axis along the bone. Should this not be switched to Z- forward so we can use it like a transform?

bug core

Most helpful comment

This is because of how bones work in Godot. This will be changed in 3.2

All 7 comments

I've spent hours trying to recalculate bone roll in blender with no usable changes to the result of looking_at, but when I use an object facing z- everything works fine. If I use a spatial+mesh facing Y+ I get the same error as blender bones produce. I'm really don't know how to fix this issue as it comes from the GLTF exporter, because the escn one doesn't produce a skeleton for me to use.

What is the intended way to make bones "look" at something? Am I supposed to add an intermediate bone in my rig for this? I want to be able to force a bone's orientation to look at or face an object but I really don't know why it is acting this way.

Is there any reason that we would keep the Y forward in the bones? Who can convert this so that bones can work with the functions provided from the Transform class?

Is there something wrong on my end of things? I really need help here guys.

Sorry to keep commenting on my own issue but im really mad at this; i've been trying to make this work for ages with my other issue just simply being archived before 3.0

What gives?

In my opinion, on the export for a bone we should set a bone's basis like so:

basis[0] = read the X Axis from blender
basis[2] = (tip - base).normalized()
basis[1] = cross(basis[0], basis[2])

Basically X axis should be coming in from blender, we calculate the Z forward based on the bone's tip, and we find the Y by crossing those two.

I'm not sure why ANYTHING BUT Z- is considered forward in Godot, even on import. This almost certainly should be converted over so we can ACTUALLY use skeletons and bones as transforms as suggested in the docs.

http://docs.godotengine.org/en/stable/tutorials/3d/working_with_3d_skeletons.html

It is a Transform, so we can do everything we can do with Transform, basically translate, rotate and scale. Also we can multiply transforms to have complex transforms. Remember, โ€œbonesโ€ in Godot are just Transforms over a group of vertices.

Haha, not quite. It acts as a broken transform unless for animation purposes where frame to frame movments aren't actually concerned with what axis points where; but in building my own IK solution I'm finding that we can't just use bones as a transform as suggested.

How are we supposed to assume this when all incoming bones have a disoriented forward direction? How could we ever reliably point an arm at a target let alone finish the half done Kine tutorial on the docs.

This really should be sorted out in my opinion.


Someone please save me I'm about to snap everything I own.

@reduz @akien-mga

Sorry to bug you two, but I have no idea if this is intended behaviour or if I'm going nuts...

I'm for sure going nuts.

I've made my own IK solver and made a PR in the demo repository. Maybe it will help?

I'm not sure if I had look_at issues or not, as it was awhile ago when I wrote the code for the look at solver. I do remember having a fair amount of trouble figuring out how to convert from bone space to world space, which was causing several problems similar to those you've mentioned (especially when the skeleton was not at origin with a rotation of (0,0,0) )

I wrote my own aswell and it just deals in Quaternions now instead of using looking_at I'm finding this works better myself. I just made a 2 bone system instead of using FABRIK however.

This is because of how bones work in Godot. This will be changed in 3.2

There have been changes to Skeleton and bones in 3.2, how is the current status for this issue in the latest 3.2 betas or later?

Was this page helpful?
0 / 5 - 0 ratings