- Edited
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