Управление в Godot Engine 4
У меня есть 3D проект в Godot (шутер от первого лица), и для игрока естественно нужен скрипт управления и перемещения. Но из-за определённых строк в коде, которые необходимы для перемещения игрока, игра запускается, но не отвечает и зависает. Причём этот же код прекрасно работал на предыдущих версиях. Вот сам код:
extends CharacterBody3D
const ROT = 0.01
const Gr = -20
const SPEED = 120
var vel = Vector3()
const J_SPEED = 10
var rot_x = 0
var rot_y = 0
func _ready():
Input.set_mouse_mode(Input.MOUSE_MODE_CAPTURED)
func _physics_process(delta):
var dir = Vector3()
if Input.is_action_just_pressed("ui_cancel"):
get_tree().quit()
if Input.is_action_just_pressed("ui_left"):
dir.x = -1
if Input.is_action_just_pressed("ui_right"):
dir.x = 1
if Input.is_action_just_pressed("ui_down"):
dir.z = 1
if Input.is_action_just_pressed("ui_up"):
dir.z = -1
if dir:
dir *= SPEED * delta
dir = dir.rotated(Vector3(0,1,0), rotation.y)
vel.x = dir.x
vel.z = dir.z
if Input.is_action_just_pressed("ui_select"):
if is_on_floor():
vel.y = J_SPEED
vel.y += Gr * delta
vel = move_and_slide(vel, Vector3(0,1,0))
func _input(e):
if e is InputEventMouseMotion:
rot_y -= e.relative.x * ROT
rot_x -= e.relative.y * ROT
if rot_x < -1: rot_x = -1
if rot_x > 1: rot_x = 1
transform.basis = Basis(Vector3(0,1,0), rot_y)
$cam.transform.basis = Basis(Vector3(1,0,0), rot_x)
Ошибка возникает при наличии строк:
vel.x = dir.x
vel.z = dir.z
vel = move_and_slide(vel, Vector3(0,1,0))