Hi everyone, please i'm looking for a solution for a problem that i meet.

i'm beginner and i'm learning the game development with godot. I make a character wih several animation that i can manipulate from animationtree. i'd like make a rotation of character's head who follow the player, but i can't recuperate the head for make a lookat to the player from a bone. Have you a way of solution please. Thank a lot to the volunter person who can help me on this contraint.

Here the code :

extends CharacterBody3D


const SPEED = 7.5
var hero
@export var turn_speed = 4.0

@onready var bone = $AnimalArmature/Skeleton3D.get_node("Head")

# Get the gravity from the project settings to be synced with RigidBody nodes.
var chasing = false

func _physics_process(delta):	
	if Input.is_action_just_pressed("quit"):
		get_tree().quit()
		
	hero = get_tree().get_nodes_in_group("Player_joueur")[0]
	$AnimationTree.set("parameters/conditions/Idle", chasing == false)
	$FaceDirection.look_at(hero.global_transform.origin, Vector3.UP)
	
	if chasing == true:	
		rotate_y(deg_to_rad($FaceDirection.rotation.y * turn_speed))
		$NavigationAgent3D.set_target_position(hero.global_transform.origin)
		var velocity = ($NavigationAgent3D.get_next_path_position() - transform.origin).normalized() * SPEED * delta
		move_and_collide(velocity)
	else:
		chasing = false
	#var bone_id = $AnimalArmature/Skeleton3D.get_bone_pose_rotation("Head")
	#$AnimalArmature/Skeleton3D.set_bone_pose_rotation(bone_id, Quaternion.from_euler(Vector3(0.0,0.0,-45.0)))
		#bone_id.look_at(hero.global_transform.origin, Vector3.UP)
		#bone.look_at(hero.global_transform.origin, Vector3(0, 1, 0))
	#var bone_h = get_node("$AnimalArmature/Skeleton3D/Head")
	#print(bone_h)
	pass

func _on_area_3d_body_entered(body):
	if body.is_in_group("Player_joueur"):
		chasing = true
		$AnimationTree.set("parameters/conditions/Gallop", chasing == true)		
		print("touche mon ami")
	pass # Replace with function body.

Long alive to godot 🧡

    I’m not sure if the bone manipulation demo from Godot 3.X was ported or not to Godot 4.X, but if it was, then there should be an example there showing how to use LookAt with a bone.
    Edit: the code is still there, so maybe it works with Godot 4.0?

    There was going to be a built in Godot 4.X IK system that would allow LookAt and a bunch of other IK solvers, but it was removed from Godot 4.X due to issues that caused it to break after the Skeleton3D bone internals were changed heavily without changing the IK accordingly.
    However, I have a Godot 4.0 IK plugin that was based on that work I did and has a few extra IK solvers that might be helpful. It includes LookAt as well 🙂

      Loxyrak Merci pour ta réponse je vais fouiner de ce coté. Bien que je sois novice, je vais me casser la tête a fouiner encore avant que tu puisses vraiment m'aider (histoire que tu fasses pas tout le taf a ma place ^^ ).

      TwistedTwigleg Thanks for your answer, i'll make fews research with the link and information that you gave me. but have you one video that show how i can use the LookAt fonction on a bone ? I'll answer here if i have a good or bad come back.

      Thank a lot to you
      Merci beaucoup à vous

      kana

      a month later

      Loxyrak Bonsoir es tu sur discord stp ? Je me sens tellement isole dans mon dev, j'ai besoin d'avis et de conseil bienveillant sur un projet en cours fait sur Godot 4.

      Cordialement

        I have code that does similar functions, set it up for yourself:

        $Character_Soldier/CharacterArmature.look_at(transform.origin - direction, Vector3.UP)

        or

        $CharacterArmature.rotation.y = lerp_angle($CharacterArmature.rotation.y, atan2(vel.x,vel.z), delta * 10)