Attention | Topic was automatically imported from the old Question2Answer platform. | |
Asked By | nikolacvijanov |
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_” + animation_direction
What is confusing is that it works for a loop or to and than it breaks
extends KinematicBody2D
onready var path_follow = get_parent()
var speed = 350
var move_direction = 0
func _ready():
pass
func _physics_process(delta):
movement_loop(delta)
func _process(delta):
animation_loop(delta)
func movement_loop(delta):
var prepos = path_follow.get_global_position()
path_follow.set_offset(path_follow.get_offset() + speed * delta)
var pos = path_follow.get_global_position()
move_direction = (pos.angle_to_point(prepos) / 3.14) * 180
func animation_loop(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)