Fixed player movement and added camera rotation

This commit is contained in:
Alexey 2025-07-15 21:12:39 +03:00
commit 2a809c857a
3 changed files with 22 additions and 5 deletions

View file

@ -2,14 +2,18 @@ extends CharacterBody3D
@export var speed = 100.0
@export var fall_acceleration = 75.0
@export var vertical_sensivity = 0.005
@export var horizontal_sensivity = 0.005
var stack: CommandStack = CommandStack.new()
@onready var camera: Camera3D = $"Camera"
@onready var weapon_player: AnimationPlayer = $"HUD/Weapon/AnimationPlayer"
# Called when the node enters the scene tree for the first time.
func _ready() -> void:
weapon_player.current_animation = "static"
Input.mouse_mode = Input.MOUSE_MODE_CAPTURED
# Called every frame. 'delta' is the elapsed time since the previous frame.
@ -17,11 +21,20 @@ func _physics_process(delta: float) -> void:
var direction = Vector3.ZERO
direction.z = Input.get_axis("move_forward", "move_backward")
direction.x = Input.get_axis("move_left", "move_right")
var target_velocity = direction * speed * delta
var target_velocity = (transform.basis * direction).normalized() * speed * delta
if not is_on_floor():
target_velocity.y -= fall_acceleration * delta
velocity = target_velocity
move_and_slide()
func _input(event):
if event is InputEventMouseMotion:
var new_rotation = clamp(
camera.rotation.x - event.relative.y * vertical_sensivity,
-PI/2,
PI/2
)
camera.rotation.x = new_rotation
rotation.y -= event.relative.x * horizontal_sensivity