Код для бега и передвижения в нашей игре
extends CharacterBody3D
# Переменные, отвечающие за скорость и управление персонажем
@export var player_speed = 8.0
@export var player_speed_run = 16.0
@export var player_acceleration = 5.0
var direction = Vector3.ZERO
var velocity = Vector3.ZERO
var is_jumping = false
func _process(delta):
if StateMachine.current_state == StateMachine.States.PLAY:
direction = Input.get_axis("ui_left", "ui_right") * head.basis.x + Input.get_axis("forward", "backward") * head.basis.z
# Проверка нажатия клавиши Shift для бега
var current_speed = player_speed
if Input.is_key_pressed(KEY_SHIFT):
current_speed = player_speed_run
if direction != Vector3.ZERO and is_on_floor():
play_sound(run_sound)
velocity = velocity.lerp(direction * current_speed + velocity.y * Vector3.UP, player_acceleration * delta)
# Обработка прыжка
if Input.is_action_just_pressed("jump") and is_on_floor():
velocity.y += jump_force
is_jumping = true
play_sound(jump_sound)
else:
if not is_on_floor() and is_jumping:
velocity.y -= gravity * delta
elif is_on_floor() and is_jumping:
is_jumping = false
play_sound(land_sound)
elif not is_on_floor():
velocity.y -= gravity * delta
move_and_slide(velocity, Vector3.UP)
func play_sound(sound):
if sound and not is_sound_playing:
is_sound_playing = true
sound.play()
Имя Фамилия
ты знаешь машину состояний?
Jul 15 2024 06:24
VORONGO
Имя Фамилия, да
Jul 15 2024 06:31 
1