ооооо

This commit is contained in:
Enikeevtimur
2022-04-18 22:37:09 +07:00
parent d911dce62a
commit dfbdf7ad31
1505 changed files with 696529 additions and 513 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,25 @@ public class scr_CharacterController : MonoBehaviour
private float cameraHeight;
private float cameraHeightVelocity;
private bool isSprinting;
[HideInInspector]
public bool isSprinting;
public bool isWalking;
private Vector3 newMovementSpeed;
private Vector3 newMovementSpeedVelocity;
[Header("Weapon")] public scr_WeaponController currentWeapon;
//[Header("Weapon")]
[HideInInspector]
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 +91,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;
@ -104,11 +143,14 @@ public class scr_CharacterController : MonoBehaviour
private void CalculateMovement()
{
if (input_Movement.y <= 0.2f)
if (input_Movement.y <= 0.3f)
{
isSprinting = false;
}
if (input_Movement.y <= 0.2f)
{
isWalking = false;
}
var verticalSpeed = playerSettings.WalkingForwardSpeed;
var horizontalSpeed = playerSettings.WalkingStrafeSpeed;
@ -119,6 +161,7 @@ public class scr_CharacterController : MonoBehaviour
}
// Effectors
if (!characterController.isGrounded)
{
playerSettings.SpeedEffector = playerSettings.FallingSpeedEffector;
@ -136,6 +179,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

@ -0,0 +1,23 @@
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
public class Target : MonoBehaviour
{
public float health = 50f;
public void TakeDamage(float amount)
{
health -= amount;
if (health <= 0f)
{
Die();
}
}
void Die()
{
Destroy(gameObject);
}
}

11
Assets/Scripts/Weapons/Target.cs.meta generated Normal file
View File

@ -0,0 +1,11 @@
fileFormatVersion: 2
guid: a364397d782009d4f8075d72f07ae2d9
MonoImporter:
externalObjects: {}
serializedVersion: 2
defaultReferences: []
executionOrder: 0
icon: {instanceID: 0}
userData:
assetBundleName:
assetBundleVariant:

View File

@ -0,0 +1,81 @@
using System;
using UnityEditor;
using UnityEngine;
using UnityEngine.InputSystem;
using static scr_Models;
public class scr_FullCharacterController : MonoBehaviour
{
private scr_CharacterController characterController;
[Header("Settings")]
public WeaponSettingsModel settings;
[Header("References")]
public Animator SciFiWarriorOur;
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;
}
public void Initialise(scr_CharacterController CharacterController)
{
characterController = CharacterController;
isInitialised = true;
}
public void Update()
{
if (!isInitialised)
{
return;
}
CalculateWeaponRotation();
SetWeaponAnimation();
}
private void CalculateWeaponRotation()
{
SciFiWarriorOur.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;
//newWeaponRotation.x = Mathf.Clamp(newWeaponRotation.x, ViewClampYMin, ViewClampYMax);
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()
{
SciFiWarriorOur.SetBool("isSprinting", characterController.isSprinting);
SciFiWarriorOur.SetBool("isWalking", characterController.isWalking);
}
}

View File

@ -0,0 +1,3 @@
fileFormatVersion: 2
guid: d42553a14d6745f9ab94d91cc5e1850a
timeCreated: 1650274114

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);
}
}