пінгвін ходіт

This commit is contained in:
MrTorex committed 2026-01-31 00:02:35 +03:00
1 parent 158850aa45
commit 0090d6d774
10 files changed
+545 -13

No files matched your search

+3
View File
@@ -0,0 +1,3 @@
fileFormatVersion: 2
guid: 6d1cbbd4cb454d23a8d6c16c6ef12c7b
timeCreated: 1769791134
+3
View File
@@ -0,0 +1,3 @@
fileFormatVersion: 2
guid: 6158f3abaa124e198d646274f7cea710
timeCreated: 1769791162
@@ -0,0 +1,90 @@
using UnityEngine;
using Code.Input;
namespace Code.Gameplay.Player
{
public class PlayerMovement : MonoBehaviour
{
[Header("References")]
[SerializeField] private Rigidbody2D _rb;
[SerializeField] private Transform _groundCheck;
[SerializeField] private LayerMask _groundLayer;
[Header("Movement")]
[SerializeField] private float _moveSpeed = 5f;
[SerializeField] private float _sprintSpeedMultiplier = 1.8f;
[SerializeField] private float _jumpForce = 12f;
[Header("Ground Check")]
[SerializeField] private float _groundCheckRadius = 0.2f;
private IInputService _input;
private bool _isGrounded;
private bool _jumpRequested;
public bool IsGrounded => _isGrounded;
public void Construct(IInputService input)
{
_input = input;
}
private void Update()
{
HandleInput();
CheckGround();
}
private void FixedUpdate()
{
Move();
HandleJump();
}
private void HandleInput()
{
transform.rotation = _input.MoveInput switch
{
> 0 => Quaternion.identity,
< 0 => Quaternion.Euler(0, -180, 0),
_ => transform.rotation
};
if (_input.JumpPressed && !_jumpRequested)
{
_jumpRequested = true;
}
}
private void CheckGround()
{
_isGrounded = Physics2D.OverlapCircle(_groundCheck.position, _groundCheckRadius, _groundLayer);
}
private void Move()
{
float moveInput = _input.MoveInput;
float speed = _input.SprintHeld ? _moveSpeed * _sprintSpeedMultiplier : _moveSpeed;
float targetVelocityX = moveInput * speed;
// Плавное изменение скорости (опционально, можно и напрямую)
_rb.linearVelocity = new Vector2(targetVelocityX, _rb.linearVelocity.y);
}
private void HandleJump()
{
if (_jumpRequested && _isGrounded)
{
_rb.linearVelocity = new Vector2(_rb.linearVelocity.x, _jumpForce);
_jumpRequested = false;
}
}
// Для отладки
private void OnDrawGizmosSelected()
{
if (_groundCheck != null)
Gizmos.DrawWireSphere(_groundCheck.position, _groundCheckRadius);
}
}
}
@@ -0,0 +1,3 @@
fileFormatVersion: 2
guid: 0c9ba2abef40495ca9fdfbe42f74330d
timeCreated: 1769791173
+3
View File
@@ -12,6 +12,9 @@ namespace Code.Input
Vector2 MainMenuParalax { get; }
float MoveInput { get; }
bool JumpPressed { get; }
bool SprintHeld { get; }
bool AttackPressed { get; }
void DebugBindAction(int mapId, int actionId, Action<InputAction.CallbackContext> action);
+6
View File
@@ -11,6 +11,9 @@ namespace Code.Input
public Vector2 MainMenuParalax { get; private set; }
public float MoveInput { get; private set; }
public bool JumpPressed { get; private set; }
public bool SprintHeld { get; private set; }
public bool AttackPressed { get; private set; }
public InputService(InputActionAsset inputActionAsset)
{
@@ -28,6 +31,9 @@ namespace Code.Input
{
var map = _inputActionAsset.actionMaps[(int)ActionMapping.Gameplay];
BindAxis(map, "Move", v => MoveInput = v);
BindButton(map, "Jump", v => JumpPressed = v);
BindButton(map, "Sprint", v => SprintHeld = v);
BindButton(map, "Attack", v => AttackPressed = v);
}
private void SetupMainMenuInputCallbacks()
+3 -5
View File
@@ -1,4 +1,5 @@
using Code.DI;
using Code.Gameplay.Player;
using Code.Input;
using UnityEngine;
@@ -12,11 +13,8 @@ namespace Code.UI
{
_inputService = FindFirstObjectByType<DIContainer>().Resolve<IInputService>();
_inputService.EnableMap(ActionMapping.Gameplay);
}
public void Update()
{
Debug.Log(_inputService.MoveInput);
FindFirstObjectByType<PlayerMovement>().Construct(_inputService);
}
}
}