Initial. Added files
This commit is contained in:
48
Assets/Scripts/Weapons/scr_WeaponController.cs
Executable file
48
Assets/Scripts/Weapons/scr_WeaponController.cs
Executable file
@ -0,0 +1,48 @@
|
||||
using System;
|
||||
using UnityEngine;
|
||||
using static scr_Models;
|
||||
public class scr_WeaponController : MonoBehaviour
|
||||
{
|
||||
private scr_CharacterController characterController;
|
||||
[Header("Settings")]
|
||||
public WeaponSettingsModel settings;
|
||||
|
||||
private bool isInitialised;
|
||||
|
||||
Vector3 newWeaponRotation;
|
||||
Vector3 newWeaponRotationVelocity;
|
||||
|
||||
Vector3 targetWeaponRotation;
|
||||
Vector3 targetWeaponRotationVelocity;
|
||||
|
||||
private void Start()
|
||||
{
|
||||
newWeaponRotation = transform.localRotation.eulerAngles;
|
||||
}
|
||||
|
||||
public void Initialise(scr_CharacterController CharacterController)
|
||||
{
|
||||
characterController = CharacterController;
|
||||
isInitialised = true;
|
||||
}
|
||||
|
||||
public void Update()
|
||||
{
|
||||
if (!isInitialised)
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
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 = Vector3.SmoothDamp(targetWeaponRotation, Vector3.zero, ref targetWeaponRotationVelocity, settings.SwayResetSmoothing);
|
||||
newWeaponRotation = Vector3.SmoothDamp(newWeaponRotation, targetWeaponRotation, ref newWeaponRotationVelocity, settings.SwaySmoothing);
|
||||
|
||||
transform.localRotation = Quaternion.Euler(newWeaponRotation);
|
||||
}
|
||||
}
|
11
Assets/Scripts/Weapons/scr_WeaponController.cs.meta
generated
Executable file
11
Assets/Scripts/Weapons/scr_WeaponController.cs.meta
generated
Executable file
@ -0,0 +1,11 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 088bf904d7c90a44dbb35c1d47c2692e
|
||||
MonoImporter:
|
||||
externalObjects: {}
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
Reference in New Issue
Block a user