LisKiril commit
This commit is contained in:
@ -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;
|
||||
|
||||
|
Reference in New Issue
Block a user