character controller is working

This commit is contained in:
MrTorex committed 2026-02-23 11:55:43 +03:00
1 parent c12d653cbc
commit 43ddb1b3b5
460 files changed
+613 -115269

No files matched your search

+20 -31
View File
@@ -6,15 +6,13 @@ namespace Code.Gameplay.Camera
{
public class CameraController : MonoBehaviour
{
[Header("Settings")]
[SerializeField] private float rotationSpeed = 300f;
[SerializeField] private float rotationSharpness = 10f;
[SerializeField] private float followSharpness = 10f;
[SerializeField] private float minVerticalAngle = -90f;
[SerializeField] private float maxVerticalAngle = 90f;
[SerializeField] private float defaultVerticalAngle = 0f;
[SerializeField] private float rotationSpeed = 0.3f;
[SerializeField] private float rotationSharpness = 50f;
[SerializeField] private float followSharpness = 50f;
[SerializeField] private float minVerticalAngle = -60f;
[SerializeField] private float maxVerticalAngle = 60f;
[SerializeField] private float defaultVerticalAngle;
[Header("Target")]
[SerializeField] private Transform followTransform;
private UnityEngine.Camera _camera;
@@ -50,7 +48,7 @@ namespace Code.Gameplay.Camera
private void LateUpdate()
{
if (followTransform != null)
if (followTransform)
{
UpdateCamera(Time.deltaTime, GetLookInput());
}
@@ -58,27 +56,22 @@ namespace Code.Gameplay.Camera
private void UpdateCamera(float deltaTime, Vector3 lookInput)
{
// Handle rotation
Quaternion targetRotation = HandleRotation(deltaTime, lookInput);
// Handle position
var targetRotation = HandleRotation(deltaTime, lookInput);
HandlePosition(deltaTime, targetRotation);
}
private Quaternion HandleRotation(float deltaTime, Vector3 lookInput)
{
// Horizontal rotation
Quaternion horizontalRotation = Quaternion.Euler(Vector3.up * (lookInput.x * rotationSpeed));
var horizontalRotation = Quaternion.Euler(Vector3.up * (lookInput.x * rotationSpeed));
_planarDirection = horizontalRotation * _planarDirection;
Quaternion planarRotation = Quaternion.LookRotation(_planarDirection, followTransform.up);
// Vertical rotation
var planarRotation = Quaternion.LookRotation(_planarDirection, followTransform.up);
_targetVerticalAngle -= lookInput.y * rotationSpeed;
_targetVerticalAngle = Mathf.Clamp(_targetVerticalAngle, minVerticalAngle, maxVerticalAngle);
Quaternion verticalRotation = Quaternion.Euler(_targetVerticalAngle, 0, 0);
var verticalRotation = Quaternion.Euler(_targetVerticalAngle, 0, 0);
// Combine and apply
Quaternion targetRotation = planarRotation * verticalRotation;
var targetRotation = planarRotation * verticalRotation;
transform.rotation = Quaternion.Slerp(transform.rotation, targetRotation, deltaTime * rotationSharpness);
return targetRotation;
@@ -97,12 +90,9 @@ namespace Code.Gameplay.Camera
private Vector3 GetLookInput()
{
// Получите здесь ваш инпут (например, из Input System)
// Это пример для стандартного инпута:
return _inputService.MoveInput;
return _inputService.LookInput;
}
// Публичные методы для получения данных
public Quaternion GetCameraRotation()
{
return transform.rotation;
@@ -113,15 +103,14 @@ namespace Code.Gameplay.Camera
return _planarDirection;
}
// Метод для установки цели следования
public void SetFollowTransform(Transform target)
{
followTransform = target;
if (target != null)
{
_currentFollowPosition = target.position;
_planarDirection = target.forward;
}
if (target == null) return;
_currentFollowPosition = target.position;
_planarDirection = target.forward;
}
}
}
@@ -1,3 +1,4 @@
using Code.DI;
using Code.Gameplay.Camera;
using Code.Gameplay.Character.Controller;
using Code.Input;
@@ -15,6 +16,11 @@ namespace Code.Gameplay.Character.Core
private IInputService _inputService;
private void Start()
{
_inputService = FindFirstObjectByType<DIContainer>().Resolve<IInputService>();
}
public void Teleport(Vector3 position, Quaternion rotation)
{
customCharacterController.SetPosition(position);
@@ -22,7 +22,7 @@ namespace Code.Gameplay.Character.Controller
public void SetPosition(Vector3 position) => motor.SetPosition(position);
public void SetRotation(Quaternion rotation) => motor.SetRotation(rotation);
private void Construct()
private void Start()
{
_inputHandler = new CharacterInputHandler(
sprintAngleThreshold
+1
View File
@@ -32,6 +32,7 @@ namespace Code.Input
{
var map = _inputActionAsset.actionMaps[(int)ActionMapping.Gameplay];
BindVector2(map, "Move", v => MoveInput = v);
BindVector2(map, "Look", v => LookInput = v);
BindButton(map, "Jump", v => JumpPressed = v);
BindButton(map, "Sprint", v => SprintHeld = v);
BindButton(map, "Attack", v => AttackPressed = v);
+2 -2
View File
@@ -1,3 +1,3 @@
fileFormatVersion: 2
guid: 6c532ef1913b4c80be438be2b66525e3
timeCreated: 1771430858
guid: 80db5060cf83494192805ee6ee7a6229
timeCreated: 1771835156
+26
View File
@@ -0,0 +1,26 @@
using UnityEngine;
using UnityEngine.SceneManagement;
using UnityEngine.UI;
namespace Code.UI
{
public class MainMenuController : MonoBehaviour
{
[SerializeField] private Button playButton;
private void Start()
{
playButton.onClick.AddListener(LoadGameplay);
}
private void LoadGameplay()
{
SceneManager.LoadScene("Gameplay");
}
private void OnDestroy()
{
playButton.onClick.RemoveAllListeners();
}
}
}
@@ -0,0 +1,3 @@
fileFormatVersion: 2
guid: 5e53c272ac334f9cb0ebd3c4dcbcc00e
timeCreated: 1771835173