0 votes
extends KinematicBody2D

const ACCELERATION = 500
const MAX_SPEED = 100
const FRICTION = 500

var velocity = Vector2.ZERO

onready var animationPlayer = $AnimationPlayer
onready var animationTree = $AnimationPlayer
onready var animationState = animationTree.get("parameters/playback")

func physicsprocess(delta):
var inputvector = Vector2.ZERO
vector.x = Input.getactionstrength("uiright") - Input.getactionstrength("uileft")
inputvector.y = Input.getactionstrength("uidown") - Input.getactionstrength("uiup")
vector = input_vector.normalized()

if input_vector != Vector2.ZERO:
    animationTree.set("parameters/Idle/blend_position", input_vector)
    animationTree.set("parameters/Run/blend_position", input_vector)
    velocity = velocity.move_toward(input_vector * MAX_SPEED, ACCELERATION * delta)     
    velocity = velocity.move_toward(Vector2.ZERO, FRICTION * delta)

velocity = move_and_slide(velocity)
in Engine by (12 points)

1 Answer

0 votes

If a node resolves to nil (or nothing) it's usually a timing issue. Try changing

onready var animationState = animationTree.get("parameters/playback")


onready var animationState = $AnimationPlayer.get("parameters/playback")

You may have to just declare animationState as a normal variable then in the _ready() function assign it to $AnimationPlayer.get("parameters/playback")

by (3,665 points)
Welcome to Godot Engine Q&A, where you can ask questions and receive answers from other members of the community.

Please make sure to read How to use this Q&A? before posting your first questions.
Social login is currently unavailable. If you've previously logged in with a Facebook or GitHub account, use the I forgot my password link in the login box to set a password for your account. If you still can't access your account, send an email to webmaster@godotengine.org with your username.