character controller is working
This commit is contained in:
1 parent
c12d653cbc
commit
43ddb1b3b5
460 files changed
+613
-115269
No files matched your search
@@ -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
|
||||
|
||||
Reference in new issue
Block a user