This commit is contained in:
aurinex
2025-08-07 17:58:10 +05:00
commit b7ccc4e3d3
24 changed files with 2006 additions and 0 deletions

29
scripts/3d_godot_robot.gd Normal file
View File

@ -0,0 +1,29 @@
extends Node3D
class_name Body
const LERP_VELOCITY: float = 0.15
@export_category("Objects")
@export var _character: CharacterBody3D = null
@export var animation_player: AnimationPlayer = null
func animate(_velocity: Vector3) -> void:
if not _character.is_on_floor():
if _velocity.y < 0:
animation_player.play("fall")
else:
animation_player.play("up")
return
if _velocity.length() > 0.1: # Если есть движение
if _character.is_running():
animation_player.play("run") # Спринт
else:
animation_player.play("walk") # Обычная ходьба
return
animation_player.play("idle") # Бездействие
@rpc("any_peer", "reliable")
func sync_player_rotation(rotation_y: float) -> void:
rotation.y = rotation_y

View File

@ -0,0 +1 @@
uid://3antcjs38iwb

82
scripts/player.gd Normal file
View File

@ -0,0 +1,82 @@
extends CharacterBody3D
class_name Character
@export_group("Movement Settings")
@export var normal_speed: float = 6.0
@export var sprint_speed: float = 10.0
@export var jump_velocity: float = 10.0
@export var gravity_scale: float = 1.0 # Позволяет регулировать гравитацию
@export var rotation_speed: float = 10.0
@export_group("References")
@export var body: Node3D = null
@export var spring_arm_offset: Node3D = null
@export var respawn_point: Vector3 = Vector3(0, 5, 0)
var _current_speed: float
var gravity = ProjectSettings.get_setting("physics/3d/default_gravity")
func _ready():
$SpringArmOffset/SpringArm3D/Camera3D.current = false
func _physics_process(delta):
var current_scene = get_tree().get_current_scene()
if not is_on_floor():
velocity.y -= gravity * delta
if is_on_floor():
if Input.is_action_just_pressed("jump"):
velocity.y = jump_velocity
else:
velocity.y -= gravity * delta
_move()
move_and_slide()
if body and body.has_method("animate"):
body.animate(velocity)
func _process(_delta):
_check_fall_and_respawn()
func freeze():
velocity.x = 0
velocity.z = 0
_current_speed = 0
func _move() -> void:
var input_direction = Input.get_vector("move_left", "move_right", "move_forward", "move_backward")
# Получаем направление движения относительно камеры
var camera_basis = $SpringArmOffset/SpringArm3D/Camera3D.global_transform.basis
var direction = (camera_basis * Vector3(input_direction.x, 0, input_direction.y)).normalized()
_update_speed()
if direction:
velocity.x = direction.x * _current_speed
velocity.z = direction.z * _current_speed
# Поворачиваем тело персонажа в направлении движения
if velocity.length() > 0.1: # Только если есть значительное движение
var target_rotation = atan2(velocity.x, velocity.z)
body.rotation.y = lerp_angle(body.rotation.y, target_rotation, rotation_speed * get_process_delta_time())
else:
velocity.x = move_toward(velocity.x, 0, _current_speed)
velocity.z = move_toward(velocity.z, 0, _current_speed)
func is_running() -> bool:
return Input.is_action_pressed("shift") and _current_speed == sprint_speed
func _update_speed() -> void:
_current_speed = sprint_speed if Input.is_action_pressed("shift") else normal_speed
func _check_fall_and_respawn():
if global_transform.origin.y < -15.0:
_respawn()
func _respawn():
global_transform.origin = respawn_point
velocity = Vector3.ZERO

1
scripts/player.gd.uid Normal file
View File

@ -0,0 +1 @@
uid://c34hkc8bu3wrg

View File

@ -0,0 +1,28 @@
extends Node3D
class_name SpringArmCharacter
const MOUSE_SENSIBILITY: float = 0.005
@export_category("Objects")
@export var _spring_arm: SpringArm3D = null
var mouse_captured: bool = true
func _ready():
Input.set_mouse_mode(Input.MOUSE_MODE_CAPTURED) # Захватываем мышь при старте
func _unhandled_input(event) -> void:
if event.is_action_pressed("ui_cancel") or event.is_action_pressed("toggle_mouse_capture"):
toggle_mouse_capture()
if mouse_captured and (event is InputEventMouseMotion):
rotate_y(-event.relative.x * MOUSE_SENSIBILITY)
_spring_arm.rotate_x(-event.relative.y * MOUSE_SENSIBILITY)
_spring_arm.rotation.x = clamp(_spring_arm.rotation.x, -PI/4, PI/24)
func toggle_mouse_capture():
mouse_captured = !mouse_captured
if mouse_captured:
Input.set_mouse_mode(Input.MOUSE_MODE_CAPTURED)
else:
Input.set_mouse_mode(Input.MOUSE_MODE_VISIBLE)

View File

@ -0,0 +1 @@
uid://7ddexruyiiqd