我正试图获得一个运动体,以便在其遵循路径时将其动画更改为适当的等距动画。我正在使用的代码如下,并将其附加到A KinematicBody2D。任何想法甚至对结构等的更改都会有所帮助。
Game
--TileMap
----Pathe2D
------PatheFollow2D
--------KinematicBody2D
--------CollisionShape2D
--------AnimationSprite
当前代码
extends KinematicBody2D
var direction = Vector2()
var currentdirection = Vector2(0,0)
# Called when the node enters the scene tree for the first time.
func _ready():
set_physics_process(true)
func _physics_process(delta):
var dir = position
var direction = dir.normalized()
print(position)
ghost_anim(dir)
# Moves Ghost
get_parent().set_offset(get_parent().get_offset() + 250 * delta)
func ghost_anim(direction):
var spritedir
if currentdirection != direction:
if currentdirection == Vector2(-1,-1):
spritedir = "Back_Left"
elif currentdirection == Vector2(1,-1):
spritedir = "Back_Right"
elif direction == Vector2(-1,1):
spritedir = "Front_Left"
elif direction == Vector2(1,1):
spritedir = "Front_Right"
else:
pass
else:
spritedir = "Front_Left"
get_node("Ghost").set_animation(spritedir)
currentdirection = direction
return currentdirection