mirror of
https://gitee.com/freeyz/godot-mota.git
synced 2024-12-23 07:19:19 +08:00
37 lines
1.1 KiB
GDScript
37 lines
1.1 KiB
GDScript
tool
|
|
extends KinematicBody2D
|
|
|
|
class_name PlayerKinematicBody2D
|
|
|
|
export(NodePath) var navigation_tile_map_path : NodePath
|
|
|
|
var navigation_tile_map : NavigationTileMap
|
|
|
|
onready var array_tween : ArrayTween = $ArrayTween
|
|
|
|
onready var animation_tree : AnimationTree = $AnimationTree
|
|
|
|
# 初始化导航相关数据
|
|
func _ready():
|
|
if not navigation_tile_map_path.is_empty():
|
|
navigation_tile_map = get_node(navigation_tile_map_path)
|
|
|
|
# 监听屏幕点击事件
|
|
func _input(event):
|
|
if event is InputEventMouseButton and event.is_pressed() and navigation_tile_map != null:
|
|
var astar = navigation_tile_map.astar
|
|
var start_id = astar.get_closest_point(position)
|
|
var end_id = astar.get_closest_point(event.position)
|
|
var paths = astar.get_point_path(start_id,end_id)
|
|
animation_tree.active = true
|
|
array_tween.interpolate_array(paths)
|
|
|
|
func _on_ArrayTween_array_completed():
|
|
animation_tree.active = false
|
|
|
|
func _on_ArrayTween_array_value_step(step):
|
|
var diff = step - position
|
|
animation_tree["parameters/player/blend_position"] = diff
|
|
move_and_collide(diff)
|
|
get_viewport().get_texture()
|