I’m using the version 4.3
I’m trying to work my Animation tree into my code so that my player has animations when it moves. I have watched a bunch of tutorials that havent worked out well so far. I made two scripts one for the player and one for the modell/skin. The problem is that it shows on the models code this error: Cannot call method ‘Travel’ on a null value. I highlided the line where the error is.
class_name Knight extends Node3D
@onready var animation_tree = %AnimationTree
@onready var state_machine : AnimationNodeStateMachinePlayback = animation_tree.get(“parameters/StateMachine/playback”)
@onready var move_tilt_path : String = “parameters/StateMachine/Move/tilt/add_amount”
var run_tilt = 0.0 : set = _set_run_tilt
func _set_run_tilt(value : float):
run_tilt = clamp(value, -1.0, 1.0)
animation_tree.set(move_tilt_path, run_tilt)
func Idle():
state_machine.travel(“Idle”)
func Walk():
state_machine.travel(“Walk”)
func Run():
state_machine.travel(“Run”)
func Jump():
state_machine.travel(“Jump”)
func Attack1():
state_machine.travel(“Attack1”)
func Death():
state_machine.travel(“Death”)
and this the players script, it doesnt show any error but maybe its part of the erorr or why it wont work:
extends CharacterBody3D
@export_group(“Camera”)
@export_range(0.0, 1.0) var mouse_sensitivity := 0.25
@export_group(“Movement”)
@export var move_speed := 8.0
@export var acceleration = 20.0
@export var rotation_speed := 12.0
var _camera_input_direction := Vector2.ZERO
var _last_movement_direction := Vector3.BACK
@onready var _camera_pivot: Node3D = %CameraPivot
@onready var _camera: Camera3D = %Camera3D
@onready var _skin = %Knight
func _ready() → void:
Input.set_mouse_mode(Input.MOUSE_MODE_CAPTURED)
func _input(event: InputEvent) → void:
if event.is_action_pressed(“ui_cancel”):
Input.mouse_mode = Input.MOUSE_MODE_VISIBLE
func _unhandled_input(event: InputEvent) → void:
var is_camera_motion := (
event is InputEventMouseMotion and
Input.get_mouse_mode() == Input.MOUSE_MODE_CAPTURED
)
if is_camera_motion:
_camera_input_direction = event.screen_relative * mouse_sensitivity
func _physics_process(delta: float) → void:
_camera_pivot.rotation.x += _camera_input_direction.y *delta
_camera_pivot.rotation.x = clamp(_camera_pivot.rotation.x,-PI / 6.0, PI / 3.0)
_camera_pivot.rotation.y -= _camera_input_direction.x *delta
_camera_input_direction = Vector2.ZERO
var raw_input := Input.get_vector("left","right","forward","backward")
var forward := _camera.global_basis.z
var right := _camera.global_basis.x
var move_direction := forward * raw_input.y + right * raw_input.x
move_direction.y = 0.0
move_direction = move_direction.normalized()
velocity = velocity.move_toward(move_direction * move_speed, acceleration * delta)
move_and_slide()
if move_direction.length() > 0.2:
_last_movement_direction = move_direction
var target_angle := Vector3.BACK.signed_angle_to(_last_movement_direction, Vector3.UP)
_skin.global_rotation.y = lerp_angle(_skin.rotation.y, target_angle, rotation_speed * delta)
var ground_speed := velocity.length()
if ground_speed > 0.0:
_skin.Walk()
else:
_skin.Idle()