mirror of
https://github.com/Project-Redacted/project-hampter.git
synced 2025-06-05 02:03:14 +00:00
Upload Game
This commit is contained in:
parent
b3f494d5c2
commit
18b63ffa9b
150 changed files with 85782 additions and 0 deletions
108
Assets/Movement/Sliding.cs
Normal file
108
Assets/Movement/Sliding.cs
Normal file
|
@ -0,0 +1,108 @@
|
|||
using System.Collections;
|
||||
using System.Collections.Generic;
|
||||
using UnityEngine;
|
||||
|
||||
public class Sliding : MonoBehaviour
|
||||
{
|
||||
[Header("References")]
|
||||
public Transform orientation;
|
||||
public Transform playerObj;
|
||||
private Rigidbody rb;
|
||||
private PlayerMovement pm;
|
||||
PlayerStamina playerStamina;
|
||||
[Header("Sliding")]
|
||||
public float maxSlideTime;
|
||||
public float slideForce;
|
||||
private float slideTimer;
|
||||
|
||||
|
||||
|
||||
public float slideYScale;
|
||||
private float startYScale;
|
||||
|
||||
[Header("Input")]
|
||||
public KeyCode slideKey = KeyCode.LeftControl;
|
||||
private float horizontalInput;
|
||||
private float verticalInput;
|
||||
|
||||
|
||||
public float slideStaminaCost = 20;
|
||||
|
||||
private void Start()
|
||||
{
|
||||
rb = GetComponent<Rigidbody>();
|
||||
pm = GetComponent<PlayerMovement>();
|
||||
playerStamina = GetComponent<PlayerStamina>();
|
||||
|
||||
startYScale = playerObj.localScale.y;
|
||||
|
||||
|
||||
}
|
||||
|
||||
private void Update()
|
||||
{
|
||||
horizontalInput = Input.GetAxisRaw("Horizontal");
|
||||
verticalInput = Input.GetAxisRaw("Vertical");
|
||||
|
||||
if (Input.GetKeyDown(slideKey) && (horizontalInput != 0 || verticalInput != 0))
|
||||
StartSlide();
|
||||
|
||||
if (Input.GetKeyUp(slideKey) && pm.sliding)
|
||||
StopSlide();
|
||||
}
|
||||
|
||||
private void FixedUpdate()
|
||||
{
|
||||
if (pm.sliding)
|
||||
SlidingMovement();
|
||||
}
|
||||
|
||||
|
||||
|
||||
private void StartSlide()
|
||||
{
|
||||
|
||||
if (!playerStamina.DecreaseByChunk(slideStaminaCost))
|
||||
{
|
||||
return;
|
||||
}
|
||||
pm.sliding = true;
|
||||
|
||||
playerObj.localScale = new Vector3(playerObj.localScale.x, slideYScale, playerObj.localScale.z);
|
||||
rb.AddForce(Vector3.down * 5f, ForceMode.Impulse);
|
||||
|
||||
slideTimer = maxSlideTime;
|
||||
}
|
||||
|
||||
private void SlidingMovement()
|
||||
{
|
||||
playerStamina.DecreaseStamina();
|
||||
|
||||
Vector3 inputDirection = orientation.forward * verticalInput + orientation.right * horizontalInput;
|
||||
|
||||
if(!pm.OnSlope() || rb.velocity.y > -0.1f)
|
||||
{
|
||||
rb.AddForce(inputDirection.normalized * slideForce, ForceMode.Force);
|
||||
slideTimer -= Time.deltaTime;
|
||||
}
|
||||
|
||||
else
|
||||
{
|
||||
rb.AddForce(pm.GetSlopeMoveDirection(inputDirection) * slideForce, ForceMode.Force);
|
||||
}
|
||||
|
||||
|
||||
if (slideTimer <= 0)
|
||||
StopSlide();
|
||||
}
|
||||
|
||||
private void StopSlide()
|
||||
{
|
||||
pm.sliding = false;
|
||||
|
||||
playerObj.localScale = new Vector3(playerObj.localScale.x, startYScale, playerObj.localScale.z);
|
||||
}
|
||||
|
||||
|
||||
|
||||
}
|
Loading…
Add table
Add a link
Reference in a new issue