LisKiril commit

This commit is contained in:
DedMoroz132
2022-04-18 15:46:10 +07:00
parent 4e1787dce9
commit 5dec06be8d
12 changed files with 5800 additions and 2900 deletions

View File

@ -3,6 +3,7 @@ using System.Collections;
using System.Collections.Generic;
using Unity.Barracuda;
using UnityEngine;
using UnityEngine.InputSystem;
using static scr_Models;
@ -11,7 +12,9 @@ public class scr_CharacterController : MonoBehaviour
private CharacterController characterController;
private DefaultInput defaultInput;
private Vector2 input_Movement;
[HideInInspector]
public Vector2 input_Movement;
[HideInInspector]
public Vector2 input_View;
@ -48,12 +51,23 @@ public class scr_CharacterController : MonoBehaviour
private float cameraHeight;
private float cameraHeightVelocity;
private bool isSprinting;
[HideInInspector]
public bool isSprinting;
private Vector3 newMovementSpeed;
private Vector3 newMovementSpeedVelocity;
[Header("Weapon")] public scr_WeaponController currentWeapon;
[Header("Weapon")]
public scr_WeaponController currentWeapon;
public float weaponAnimationSpeed;
public float damage = 10f;
public float range = 100f;
public Camera fpsCam;
public ParticleSystem muzzleFlash;
public GameObject impactEffect;
private void Awake()
{
defaultInput = new DefaultInput();
@ -75,22 +89,45 @@ public class scr_CharacterController : MonoBehaviour
characterController = GetComponent<CharacterController>();
cameraHeight = cameraHolder.localPosition.y;
if (currentWeapon)
{
currentWeapon.Initialise(this);
}
}
private void Update()
{
if (Input.GetButtonDown("Fire1"))
{
Shoot();
}
CalculateView();
CalculateMovement();
CalculateJump();
CalculateCameraHeight();
}
void Shoot()
{
muzzleFlash.Play();
RaycastHit hit;
if (Physics.Raycast(fpsCam.transform.position, fpsCam.transform.forward, out hit, range))
{
Debug.Log(hit.transform.name);
Target target = hit.transform.GetComponent<Target>();
if (target != null)
{
target.TakeDamage(damage);
}
Instantiate(impactEffect, hit.point, Quaternion.LookRotation(hit.normal));
}
}
private void CalculateView()
{
newCharacterRotation.y += playerSettings.ViewXSensetivity * (playerSettings.ViewXInverted ? -input_View.x : input_View.x) * Time.deltaTime;
@ -119,6 +156,7 @@ public class scr_CharacterController : MonoBehaviour
}
// Effectors
if (!characterController.isGrounded)
{
playerSettings.SpeedEffector = playerSettings.FallingSpeedEffector;
@ -136,6 +174,13 @@ public class scr_CharacterController : MonoBehaviour
playerSettings.SpeedEffector = 1;
}
weaponAnimationSpeed = characterController.velocity.magnitude / (playerSettings.WalkingForwardSpeed * playerSettings.SpeedEffector);
if (weaponAnimationSpeed > 1)
{
weaponAnimationSpeed = 1;
}
verticalSpeed *= playerSettings.SpeedEffector;
horizontalSpeed *= playerSettings.SpeedEffector;

View File

@ -61,7 +61,7 @@ public static class scr_Models
[Serializable]
public class WeaponSettingsModel
{
[Header("Sway")]
[Header("Weapon Sway")]
public float SwayAmount;
public bool SwayYInverted;
public bool SwayXInverted;
@ -69,6 +69,13 @@ public static class scr_Models
public float SwayResetSmoothing;
public float SwayClampX;
public float SwayClampY;
[Header("Weapon Movement Sway")]
public float MovementSwayX;
public float MovementSwayY;
public bool MovementSwayYInverted;
public bool MovementSwayXInverted;
public float MovementSwaySmoothing;
}
#endregion

View File

@ -1,20 +1,31 @@
using System;
using UnityEditor;
using UnityEngine;
using UnityEngine.InputSystem;
using static scr_Models;
public class scr_WeaponController : MonoBehaviour
{
private scr_CharacterController characterController;
[Header("Settings")]
public WeaponSettingsModel settings;
[Header("References")]
public Animator weaponAnimator;
private bool isInitialised;
Vector3 newWeaponRotation;
Vector3 newWeaponRotationVelocity;
Vector3 targetWeaponRotation;
Vector3 targetWeaponRotationVelocity;
Vector3 newWeaponMovementRotation;
Vector3 newWeaponRotationMovementVelocity;
Vector3 targetWeaponMovementRotation;
Vector3 targetWeaponMovementRotationVelocity;
private void Start()
{
newWeaponRotation = transform.localRotation.eulerAngles;
@ -32,6 +43,13 @@ public class scr_WeaponController : MonoBehaviour
{
return;
}
CalculateWeaponRotation();
SetWeaponAnimation();
}
private void CalculateWeaponRotation()
{
weaponAnimator.speed = characterController.weaponAnimationSpeed;
targetWeaponRotation.y += settings.SwayAmount * (settings.SwayXInverted ? -characterController.input_View.x : characterController.input_View.x) * Time.deltaTime;
targetWeaponRotation.x += settings.SwayAmount * (settings.SwayYInverted ? characterController.input_View.y : -characterController.input_View.y) * Time.deltaTime;
@ -40,9 +58,23 @@ public class scr_WeaponController : MonoBehaviour
targetWeaponRotation.x = Mathf.Clamp(targetWeaponRotation.x, -settings.SwayClampX, settings.SwayClampX);
targetWeaponRotation.y = Mathf.Clamp(targetWeaponRotation.y, -settings.SwayClampY, settings.SwayClampY);
targetWeaponRotation.z = targetWeaponRotation.y;
targetWeaponRotation = Vector3.SmoothDamp(targetWeaponRotation, Vector3.zero, ref targetWeaponRotationVelocity, settings.SwayResetSmoothing);
newWeaponRotation = Vector3.SmoothDamp(newWeaponRotation, targetWeaponRotation, ref newWeaponRotationVelocity, settings.SwaySmoothing);
targetWeaponMovementRotation.z = settings.MovementSwayX * (settings.MovementSwayXInverted ? -characterController.input_Movement.x : characterController.input_Movement.x);
targetWeaponMovementRotation.x = settings.MovementSwayY * (settings.MovementSwayYInverted ? -characterController.input_Movement.y : characterController.input_Movement.y);
targetWeaponMovementRotation = Vector3.SmoothDamp(targetWeaponMovementRotation, Vector3.zero, ref targetWeaponMovementRotationVelocity, settings.SwayResetSmoothing);
newWeaponMovementRotation = Vector3.SmoothDamp(newWeaponRotation, targetWeaponMovementRotation, ref newWeaponRotationVelocity, settings.SwaySmoothing);
transform.localRotation = Quaternion.Euler(newWeaponRotation);
}
private void SetWeaponAnimation()
{
weaponAnimator.SetBool("isSprinting", characterController.isSprinting);
}
}