我试图让一个运动体将其动画更改为适当的等距动画,因为它遵循一条路径。我正在使用的代码如下,它附加到 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