0 votes

I have set animations in animation player and they work properly

for some reason game breaks after few loops following path2d and I dont know why.
its confusing because it makes few loops without problems but eventualy allways brakes

godot says an error is:
invalid operands string and nil in operator +

and points to a line in code:
var animation = "Walk" + animationdirection

What is confusing is that it works for a loop or to and than it breaks

extends KinematicBody2D

onready var pathfollow = getparent()

var speed = 350
var move_direction = 0

func _ready():
pass

func physicsprocess(delta):
movement_loop(delta)

func process(delta):
animation
loop(delta)

func movementloop(delta):
var prepos = path
follow.getglobalposition()
pathfollow.setoffset(pathfollow.getoffset() + speed * delta)
var pos = pathfollow.getglobalposition()
move
direction = (pos.angletopoint(prepos) / 3.14) * 180

func animationloop(delta):
var animation
direction

if move_direction <= 15 and move_direction >= -15:
    animation_direction = "E"
elif move_direction <= 60 and move_direction >= 15:
    animation_direction = "SE"
elif move_direction <= 120 and move_direction >= 60:
    animation_direction = "S"
elif move_direction <= 165 and move_direction >= 120:
    animation_direction = "SW"
#elif move_direction <= 120 and move_direction >= 60:
    #animation_direction = "S"
elif move_direction >= -60 and move_direction <= -15:
    animation_direction = "NE"
elif move_direction >= -120 and move_direction <= -60:
    animation_direction = "N"
elif move_direction >= -165 and move_direction <= -120:
    animation_direction = "NW"

elif move_direction <= -165 and move_direction >= 165:
    animation_direction = "W"

var animation = "Walk_" + animation_direction
get_node("AnimationPlayer").play(animation)
Godot version 3.2.3
in Engine by (12 points)

Please log in or register to answer this question.

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.