Top.Mail.Ru
Ответы
Аватар пользователя
Изменено
Аватар пользователя
Аватар пользователя
Пояснительная бригада
+1

Помогите найти ошибку в коде godot

помогите найти ошибки в данном коде, или напишите свой, работающий, пожалуйста!

Пишу игру на godot ( версия 4.4.1. ) и столкнулся с ошибкой в довольно простом коде.

Цель кода - дать персонажу возможность передвигаться в 4 направлениях, прыгать и атаковать ( с анимацией ).

если кто знает, где ошибки, укажите пожалуйста, ну, или напишите свой который будет выполнять написанные выше задачи. заранее, большое спасибо всем, кто поможет!

вот код:

Extends CharacterBody2D

@onready var animationplayer = $AnimationPlayer

func process(delta):

if Input.is_action_pressed("left"):

animationplayer.play("walk left")

if Input.is_action_pressed("right"):

animationplayer.play("walk right")

if Input.is_action_pressed("up"):

animationplayer.play("walk up")

if Input.is_action_pressed("down"):

animationplayer.play("walk down")

if Input.is_action_pressed("fight down"):

animationplayer.play("attack down")

if Input.is_action_pressed("fight up"):

animationplayer.play("attack up")

if Input.is_action_pressed("fight left"):

animationplayer.play("attack left")

if Input.is_action_pressed("fight right"):

animationplayer.play("attack right")

else:

animationplayer.play("idle down")

var run_speed = 350

var jump_speed = -1000

var gravity = 2500

func get_input():

velocity.x = 0

var right = Input.is_action_pressed("a")

var up = input.is_action_pressed("w")

var jump = Input.is_action_just_pressed("jump")

var left = Input.is_action_pressed("d")

if is_on_floor() and jump:

velocity.y = jump_speed

if right:

velocity.x += run_speed

if left:

velocity.x -= run_speed

if up:

velocity.y =- run_speed

if down:

velocity.y =+ run_speed

func physicsprocess(delta):

velocity.y += gravity * delta

get_input()

move_and_slide()