Есть классы, есть двери, есть механика вселения, свага есть
This commit is contained in:
1 parent
2ae795c30a
commit
0f9a539460
69 files changed
+3960
-299
No files matched your search
@@ -12,6 +12,7 @@ namespace _Project.Scripts.PlayerUtils
|
||||
[SerializeField] private float crouchSpeed = 3f;
|
||||
|
||||
[Header("Параметры Подката (Slide)")]
|
||||
[SerializeField] private bool canSlide = true;
|
||||
[SerializeField] private float slideInitialSpeed = 15f;
|
||||
[SerializeField] private float slideDuration = 0.85f;
|
||||
[SerializeField] private float slideFriction = 2.8f;
|
||||
@@ -22,7 +23,6 @@ namespace _Project.Scripts.PlayerUtils
|
||||
[SerializeField] private float groundAcceleration = 10f;
|
||||
[SerializeField] private float airAcceleration = 80f;
|
||||
[SerializeField] private float airCap = 2.0f;
|
||||
[SerializeField] private bool showSpeedometer = true;
|
||||
|
||||
[Header("Гравитация и Прыжок")]
|
||||
[SerializeField] private float jumpHeight = 1.35f;
|
||||
@@ -47,6 +47,7 @@ namespace _Project.Scripts.PlayerUtils
|
||||
public bool IsSliding { get; private set; }
|
||||
public Vector2 MoveInput { get; private set; }
|
||||
public float CurrentSpeed => horizontalVelocity.magnitude;
|
||||
|
||||
private bool wasGrounded;
|
||||
private float jumpBufferTimer = 0f;
|
||||
private Vector3 horizontalVelocity = Vector3.zero;
|
||||
@@ -57,15 +58,16 @@ namespace _Project.Scripts.PlayerUtils
|
||||
private Vector3 slideDirection = Vector3.zero;
|
||||
private float slideCooldownTimer = 0f;
|
||||
|
||||
private void Start()
|
||||
private void Awake()
|
||||
{
|
||||
rb = GetComponent<Rigidbody>();
|
||||
col = GetComponent<CapsuleCollider>();
|
||||
|
||||
rb.useGravity = false;
|
||||
rb.freezeRotation = true;
|
||||
rb.interpolation = RigidbodyInterpolation.None;
|
||||
}
|
||||
|
||||
private void Start()
|
||||
{
|
||||
controls = Player.Instance.Controls;
|
||||
|
||||
controls.Player.Sprint.started += _ => IsSprinting = true;
|
||||
@@ -77,12 +79,35 @@ namespace _Project.Scripts.PlayerUtils
|
||||
controls.Player.Jump.performed += _ => QueueJump();
|
||||
}
|
||||
|
||||
public void ApplyProfile(BodyProfile profile)
|
||||
{
|
||||
moveSpeed = profile.moveSpeed;
|
||||
sprintSpeed = profile.sprintSpeed;
|
||||
crouchSpeed = profile.crouchSpeed;
|
||||
canSlide = profile.canSlide;
|
||||
slideInitialSpeed = profile.slideInitialSpeed;
|
||||
slideDuration = profile.slideDuration;
|
||||
airAcceleration = profile.airAcceleration;
|
||||
jumpHeight = profile.jumpHeight;
|
||||
gravity = profile.gravity;
|
||||
standingHeight = profile.standingHeight;
|
||||
|
||||
if (!canSlide && IsSliding) StopSlide();
|
||||
}
|
||||
|
||||
public void AddVerticalImpulse(float velocityY)
|
||||
{
|
||||
verticalVelocity = velocityY;
|
||||
IsGrounded = false;
|
||||
}
|
||||
|
||||
private void Update()
|
||||
{
|
||||
MoveInput = controls.Player.Move.ReadValue<Vector2>();
|
||||
|
||||
if (jumpBufferTimer > 0f) jumpBufferTimer -= Time.deltaTime;
|
||||
if (slideCooldownTimer > 0f) slideCooldownTimer -= Time.deltaTime;
|
||||
float dt = Time.unscaledDeltaTime;
|
||||
if (jumpBufferTimer > 0f) jumpBufferTimer -= dt;
|
||||
if (slideCooldownTimer > 0f) slideCooldownTimer -= dt;
|
||||
|
||||
if (Mouse.current != null && Mathf.Abs(Mouse.current.scroll.y.ReadValue()) > 0.1f)
|
||||
QueueJump();
|
||||
@@ -100,7 +125,11 @@ namespace _Project.Scripts.PlayerUtils
|
||||
|
||||
ApplyMovement();
|
||||
|
||||
rb.linearVelocity = new Vector3(horizontalVelocity.x, verticalVelocity, horizontalVelocity.z);
|
||||
float timeMult = Player.Instance.Possession != null ? Player.Instance.Possession.PlayerTimeMultiplier : 1f;
|
||||
rb.linearVelocity = new Vector3(
|
||||
horizontalVelocity.x * timeMult,
|
||||
verticalVelocity,
|
||||
horizontalVelocity.z * timeMult);
|
||||
wasGrounded = IsGrounded;
|
||||
}
|
||||
|
||||
@@ -108,7 +137,7 @@ namespace _Project.Scripts.PlayerUtils
|
||||
{
|
||||
bool isLowered = IsCrouching || IsSliding;
|
||||
float targetHeight = isLowered ? crouchingHeight : standingHeight;
|
||||
col.height = Mathf.Lerp(col.height, targetHeight, Time.deltaTime * crouchTransitionSpeed);
|
||||
col.height = Mathf.Lerp(col.height, targetHeight, Time.unscaledDeltaTime * crouchTransitionSpeed);
|
||||
col.center = new Vector3(col.center.x, col.height * 0.5f, col.center.z);
|
||||
}
|
||||
|
||||
@@ -126,8 +155,6 @@ namespace _Project.Scripts.PlayerUtils
|
||||
jumpBufferTimer = 0f;
|
||||
|
||||
Player.Instance.CameraController.TriggerJumpImpact();
|
||||
|
||||
// ВЫЗОВ ЗВУКА ИЗ НОВОГО МОДУЛЯ
|
||||
Player.Instance.Sound.PlayJump();
|
||||
}
|
||||
|
||||
@@ -201,7 +228,6 @@ namespace _Project.Scripts.PlayerUtils
|
||||
|
||||
if (!wasGrounded && IsGrounded)
|
||||
{
|
||||
// ВЫЗОВ ЗВУКА ИЗ НОВОГО МОДУЛЯ
|
||||
Player.Instance.Sound.PlayLand();
|
||||
}
|
||||
|
||||
@@ -217,7 +243,7 @@ namespace _Project.Scripts.PlayerUtils
|
||||
|
||||
private void OnCrouchPressed()
|
||||
{
|
||||
if (IsSprinting && IsGrounded && MoveInput.y > 0.2f && slideCooldownTimer <= 0f) StartSlide();
|
||||
if (canSlide && IsSprinting && IsGrounded && MoveInput.y > 0.2f && slideCooldownTimer <= 0f) StartSlide();
|
||||
else IsCrouching = true;
|
||||
}
|
||||
|
||||
@@ -235,7 +261,6 @@ namespace _Project.Scripts.PlayerUtils
|
||||
slideDirection = (transform.forward * MoveInput.y + transform.right * MoveInput.x).normalized;
|
||||
if (slideDirection.sqrMagnitude < 0.01f) slideDirection = transform.forward;
|
||||
|
||||
// ВЫЗОВ ЗВУКА ИЗ НОВОГО МОДУЛЯ
|
||||
Player.Instance.Sound.PlaySlide();
|
||||
}
|
||||
|
||||
@@ -244,6 +269,5 @@ namespace _Project.Scripts.PlayerUtils
|
||||
IsSliding = false;
|
||||
slideCooldownTimer = slideCooldown;
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
Reference in new issue
Block a user