1

为了清楚起见,重写和编辑。假设我有一个 2d 平台游戏,如下例所示:

https://github.com/godotengine/godot-demo-projects/blob/master/2d/kinematic_character/player.gd

现在...假设我有玩家位置(vector2)和敌人位置(vector2)。敌人的移动就像上面例子中的玩家一样。我使用 get_simple_path 来构建从敌人位置到玩家位置的预先存在的点数组。如何使用带有 move_and_slide 的数组将敌人从 A 点带到 B 点?

4

1 回答 1

0

您可以尝试以下方法:

const GRAVITY = 1000
const SLOPE_SLIDE_STOP = false

var speed = 250
var velocity = Vector2()

var points = [Vector2(100, 200), Vector2(200, 400), Vector2(400, 800)]
var current_point = null

func _physics_process(delta):
    if points and current_point is null:
        current_point = points.pop_front()

    if current_point:
        if current_point.distance_to(position) > 0:
            target_direction = (position - current_point).normalized()

            velocity.y += delta * GRAVITY

            velocity = lerp(velocity, target_speed, 0.1)
            velocity = move_and_slide(velocity, target_direction, SLOPE_SLIDE_STOP)
        else:
            current_point = null
于 2019-01-18T17:36:38.707 回答