Godot 3.0按照路径更改KinimaticBody 2D的动画

时间:2019-04-12 03:06:12

标签: isometric godot path-2d

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

0 个答案:

没有答案