Mkay, im trying to set the speed of an animation to the value of the inputs get_action_strength. this is in a state machine, this being the code for the walk state. it works as expected, but trying to add the animation speed, and things start to fall down!
at the moment it gives an error... Attempt to call function 'get_move_direction' in base 'null instance' on a null instance. to this line...
var animation_speed: float = move.get_move_direction().x same error using get_parent().get_move_direction().x
...which means its a wrong node path doesnt it? Or spelling mistake etc. which is odd, as this is called succesfully later in the code.
Entering the state, the animation is played, so thats the place to start playing with animation speed I think.
Heres the code for the state....
extends State
var move: = get_parent()
var animation_speed: float = move.get_move_direction().x
# interface for the state
func unhandled_input(event: InputEvent) -> void:
get_parent().unhandled_input(event)
func physics_process(delta: float) -> void:
var move: = get_parent()
# transitions
# 1 if input movement stops, go idle
if owner.is_on_floor():
if move.get_move_direction().x == 0.0:
_state_machine.transition_to("Move/Idle")
else:
_state_machine.transition_to("Move/Air")
if move.get_move_direction().x > 0.0:
owner.get_node("AnimatedSprite").flip_h = false
if move.get_move_direction().x < 0.0:
owner.get_node("AnimatedSprite").flip_h = true
# delegate motion to the move state...
move.physics_process(delta)
func enter(msg: Dictionary = {}) -> void:
# pass the message to the parent move state...
get_parent().enter(msg)
print(animation_speed)
owner.get_node("AnimationPlayer").play("Run").playback_speed(animation_speed)
# owner.get_node("AnimationPlayer").play("Run")
func exit() -> void:
get_parent().exit()
How do I go about setting the animation speed to the input strength? Im at head scratching stage!!