xyz Continuing debugging, i noticed:
When i click on the ball (i removed look_at() ) i print out positions of the ball and intersection.
ball_node.gd
if cam != null:
#look_at(cam.global_transform.origin,Vector3.UP)
print("interset click0: ", global_position)
temp_plane = Plane(cam.global_transform.basis.z,global_position)
var RAY_LENGTH = (cam.global_position - global_position).length()*1.1
var mousepos = get_viewport().get_mouse_position()
var origin = cam.project_ray_origin(mousepos)
var end = origin + cam.project_ray_normal(mousepos) * RAY_LENGTH
var query = PhysicsRayQueryParameters3D.create(origin, end)
query.exclude = [self]
query.collide_with_areas = true
var intersect = temp_plane.intersects_ray(end, cam.global_transform.origin-global_position)
if intersect:
ball_position_changed.emit(bone_index, intersect)
print("interset click1: ", intersect)
ball_clicked.emit(position)
Clicking the ball that is not related to bones prints out position that is close to real position of the ball.
interset click0: (0, 0.959433, -1.63808)
interset click1: (0.03866, 0.905366, -1.619112)
But when i click the ball that is attached to bone, the ball jumps to some arbitrary location and prints out that wrong location.
While i was writing this, i figured it out i think.
Previously on garbanzo..
func _on_ball_position_changed(bone_index, bone_pos):
skeleton_3d.set_bone_pose_position(bone_index,bone_pos)
pass
Working code:
func _on_ball_position_changed(bone_index, bone_pos):
var pos = bone_pos * skeleton_3d.global_transform
skeleton_3d.set_bone_pose_position(bone_index,pos)
pass
So the problem was the transforms3d as per usual..
Another culprit is that skeleton_3d.get_bone_global_pose
and skeleton_3d.set_bone_pose_position
work in local coord space relative to skeleton.
But.. as per usual, some things are still not working.. ๐.. In the video i try to move the child-bone
and this messes up everything.. mowing root-bone
works as expected.
Still need to work on the child node manipulations..