プレイヤーが WASD キーで世界中を自由に移動できる RPG を作成しています。しかし、戦闘中は、プレイヤーはマウスで制御される戦術的なグリッドベースの動きに切り替わります. これを達成するために状態を使用することを考えました。しかし、これを適切に行う方法がわかりません。
私の運動力学のコードは次のとおりです。
extends KinematicBody2D
export (int) var speed = 250
var velocity
var states = {movement:[Over_Mov, Tile_Mov]}
var current_state = null
func _ready():
current_state = Over_Mov
func get_input():
velocity = Vector2()
if Input.is_action_pressed("ui_up"):
velocity.y -= 1
elif Input.is_action_pressed("ui_down"):
velocity.y += 1
elif Input.is_action_pressed("ui_right"):
velocity.x += 1
elif Input.is_action_pressed("ui_left"):
velocity.x -= 1
velocity = velocity.normalized() * speed
func _physics_process(delta):
get_input()
move_and_collide(velocity*delta)
動きの力学にはゴドーのサンプルを使用しています。