mirror of
https://github.com/DerTyp7/defrain-shooter-unity.git
synced 2025-10-29 12:52:07 +01:00
Procedual Animation Hand Fix
See "Procedual Animation Hand Fix" issue
This commit is contained in:
@@ -1,34 +0,0 @@
|
||||
using System.Collections;
|
||||
using System.Collections.Generic;
|
||||
using UnityEngine;
|
||||
|
||||
public class AimDownSights : MonoBehaviour
|
||||
{
|
||||
[SerializeField] float aimSpeed = 0.01f;
|
||||
[SerializeField][Range(0,1)] public float aimVal = 0;
|
||||
[SerializeField] private GameObject gun;
|
||||
[SerializeField] GameObject AimPoint;
|
||||
[SerializeField] GameObject HoldPoint;
|
||||
public bool isAiming = false;
|
||||
bool ADS()
|
||||
{
|
||||
|
||||
return true;
|
||||
}
|
||||
private void FixedUpdate()
|
||||
{
|
||||
if (Input.GetButton("Aim"))
|
||||
{
|
||||
isAiming = true;
|
||||
aimVal += aimSpeed;
|
||||
}
|
||||
else
|
||||
{
|
||||
isAiming = false;
|
||||
aimVal -= aimSpeed;
|
||||
}
|
||||
aimVal = Mathf.Clamp(aimVal,0,1);
|
||||
|
||||
gun.transform.position = Vector3.Lerp(HoldPoint.transform.position, AimPoint.transform.position,Mathf.Pow(aimVal,1.3f)) ;
|
||||
}
|
||||
}
|
||||
@@ -1,11 +0,0 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 916f2d37f60a91149bbca3280a1b69ec
|
||||
MonoImporter:
|
||||
externalObjects: {}
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
@@ -1,78 +0,0 @@
|
||||
using System.Collections;
|
||||
using System.Collections.Generic;
|
||||
using UnityEngine;
|
||||
using Mirror;
|
||||
public class Headbob : NetworkBehaviour
|
||||
{
|
||||
[SerializeField] private PlayerController playerController;
|
||||
[SerializeField] private ShootAnimation gunAnimation;
|
||||
|
||||
|
||||
[SerializeField] private float posCheckDistance = 0.01f;
|
||||
[SerializeField] private float checkDist = 0.0f;
|
||||
private float currentDist = 0;
|
||||
|
||||
[Header("Step Settings")]
|
||||
[SerializeField] private float stepAmplitudeWalking;
|
||||
[SerializeField] private float stepAmplitudeSprinting;
|
||||
[SerializeField] [Range(0.01f, 10.0f)] private float stepFrequency;
|
||||
[SerializeField] private Transform Neck;
|
||||
|
||||
private Vector3 lastPos;
|
||||
private Vector3 startPos;
|
||||
private Vector3 newPos;
|
||||
private float oldDist = 0;
|
||||
private float lerpVal = 0;
|
||||
|
||||
|
||||
[Header("Gun Settings")]
|
||||
[SerializeField] GameObject gunRotation;
|
||||
[SerializeField] float rotationMultiplier = 0.1f;
|
||||
|
||||
|
||||
|
||||
private void Start()
|
||||
{
|
||||
lastPos = this.transform.position;
|
||||
//startPos = this.transform.position;
|
||||
}
|
||||
|
||||
private void Update()
|
||||
{
|
||||
|
||||
float amplitude;
|
||||
if (playerController.isGrounded)
|
||||
{
|
||||
lerpVal = 0;
|
||||
float dist = Vector3.Distance(lastPos, this.transform.position);
|
||||
if (playerController.isSprinting)
|
||||
amplitude = stepAmplitudeSprinting;
|
||||
else
|
||||
amplitude = stepAmplitudeWalking;
|
||||
|
||||
if (dist > posCheckDistance)
|
||||
{
|
||||
currentDist += dist;
|
||||
lastPos = this.transform.position;
|
||||
}
|
||||
else
|
||||
{
|
||||
checkDist = currentDist + dist;
|
||||
}
|
||||
gunAnimation.gunSideSwey(getSin(amplitude, stepFrequency/2, checkDist),playerController.inputDirection.magnitude);
|
||||
newPos = new Vector3(getSin(amplitude / 2, stepFrequency, checkDist), getSin(amplitude, stepFrequency, checkDist), 0);
|
||||
Neck.localPosition = newPos;
|
||||
}
|
||||
else
|
||||
{
|
||||
Neck.localPosition = Vector3.zero;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
private float getSin(float multiplier, float devisor,float x)
|
||||
{
|
||||
return multiplier * Mathf.Sin((x/3.14f) * 10 * devisor);
|
||||
}
|
||||
|
||||
}
|
||||
@@ -1,11 +0,0 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 4db7caf602ce379408a59c8722e06e46
|
||||
MonoImporter:
|
||||
externalObjects: {}
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
@@ -1,28 +0,0 @@
|
||||
using System.Collections;
|
||||
using System.Collections.Generic;
|
||||
using UnityEngine;
|
||||
using Mirror;
|
||||
|
||||
public class PlayerColor : NetworkBehaviour
|
||||
{
|
||||
[SyncVar(hook = "SetColor")]
|
||||
public Color color;
|
||||
public Renderer renderer;
|
||||
|
||||
void SetColor(Color oldColor, Color newColor)
|
||||
{
|
||||
if (color == null)
|
||||
{
|
||||
color = renderer.material.color;
|
||||
}
|
||||
|
||||
renderer.material.color = newColor;
|
||||
color = newColor;
|
||||
|
||||
}
|
||||
|
||||
public override void OnStartClient()
|
||||
{
|
||||
renderer.material.color = color;
|
||||
}
|
||||
}
|
||||
@@ -1,11 +0,0 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 00dc60b61b501f2419e2abd7158be5f8
|
||||
MonoImporter:
|
||||
externalObjects: {}
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
@@ -161,7 +161,6 @@ public class PlayerController : NetworkBehaviour
|
||||
moveDirection = new Vector3(moveDirection.x, 0, moveDirection.z);
|
||||
currentDir = moveDirection;
|
||||
}
|
||||
Debug.Log(currentMaxSpeed);
|
||||
velocity = Vector3.SmoothDamp(velocity, currentDir * currentMaxSpeed + new Vector3(0, velocityY, 0),ref refVelocity,moveSmoothTime);
|
||||
localVelocity = transform.InverseTransformDirection(velocity);
|
||||
controller.Move(velocity * Time.deltaTime);
|
||||
|
||||
@@ -5,6 +5,14 @@ using Mirror;
|
||||
|
||||
public class ProcedualAnimationController : NetworkBehaviour
|
||||
{
|
||||
[Header("Hand Settings")]
|
||||
[SerializeField] private Transform rightHandREF;
|
||||
[SerializeField] private Transform leftHandREF;
|
||||
[SerializeField] private Transform gunRightHandREF;
|
||||
[SerializeField] private Transform gunLeftHandREF;
|
||||
[SerializeField] private Vector3 defaultRightHandPosition = Vector3.zero;
|
||||
[SerializeField] private Vector3 defaultLeftHandPosition = Vector3.zero;
|
||||
|
||||
|
||||
[Header("Step Settings")]
|
||||
[SerializeField] private float stepAmplitudeWalking;
|
||||
@@ -99,6 +107,28 @@ public class ProcedualAnimationController : NetworkBehaviour
|
||||
playerAnimator.SetFloat("x", playerController.localVelocity.x / playerController.currentMaxSpeed);
|
||||
playerAnimator.SetFloat("y", playerController.localVelocity.z / playerController.currentMaxSpeed);
|
||||
}
|
||||
|
||||
public void handPositioning()
|
||||
{
|
||||
if (gunRightHandREF != null)
|
||||
{
|
||||
rightHandREF.position = gunRightHandREF.position;
|
||||
rightHandREF.rotation = gunRightHandREF.rotation;
|
||||
}
|
||||
else
|
||||
{
|
||||
rightHandREF.position = defaultRightHandPosition;
|
||||
}
|
||||
if (gunLeftHandREF != null)
|
||||
{
|
||||
leftHandREF.position = gunLeftHandREF.position;
|
||||
leftHandREF.rotation = gunLeftHandREF.rotation;
|
||||
}
|
||||
else
|
||||
{
|
||||
leftHandREF.position = defaultLeftHandPosition;
|
||||
}
|
||||
}
|
||||
public void OnSwitchWeapon(GameObject currentWeapon)
|
||||
{
|
||||
if (isLocalPlayer) {
|
||||
@@ -141,7 +171,7 @@ public class ProcedualAnimationController : NetworkBehaviour
|
||||
if (isLocalPlayer)
|
||||
{
|
||||
walkAnimation();
|
||||
|
||||
handPositioning();
|
||||
CmdAim(Input.GetButton("Aim"));
|
||||
}
|
||||
/*-----Aiming-----*/
|
||||
|
||||
@@ -1,156 +0,0 @@
|
||||
using System.Collections;
|
||||
using System.Collections.Generic;
|
||||
using UnityEngine;
|
||||
|
||||
public class ShootAnimation : MonoBehaviour
|
||||
{
|
||||
|
||||
[Header("GameObjects")]
|
||||
[SerializeField] private GameObject gun;
|
||||
[SerializeField] private GameObject gunHolder;
|
||||
[SerializeField] private GameObject gunPositionObj;
|
||||
[SerializeField] private GameObject gunRotationObj;
|
||||
|
||||
|
||||
[Header("Settings")]
|
||||
[SerializeField] bool positionRecoil = true;
|
||||
[SerializeField] bool rotationRecoil = true;
|
||||
|
||||
[Header("Position Settings")]
|
||||
[SerializeField] float positionMultX = 25f;
|
||||
[SerializeField] float positionMultY = 25f;
|
||||
[SerializeField] float positionMultZ = 25f;
|
||||
|
||||
[Header("Rotation Settings")]
|
||||
[SerializeField] PlayerMouseLook playerMouseLook;
|
||||
[SerializeField] float cameraRecoilX = 0.1f;
|
||||
[SerializeField] float cameraRecoilY = 0.1f;
|
||||
|
||||
|
||||
[SerializeField] bool rotX = true;
|
||||
[SerializeField] float rotationMultX = 25f;
|
||||
[SerializeField] float rotationOffsetX = 0.1f;
|
||||
[SerializeField] bool rotY = true;
|
||||
[SerializeField] float rotationMultY = 25f;
|
||||
[SerializeField] bool rotZ = true;
|
||||
[SerializeField] float rotationMultZ = 15f;
|
||||
|
||||
[Header("Swey Settings")]
|
||||
[SerializeField] AimDownSights ADSController;
|
||||
[SerializeField] bool sideSwey = true;
|
||||
[SerializeField] float sweyMult = 15f;
|
||||
[SerializeField] float sweyWhileAim = 0.1f;
|
||||
float swey = 0f;
|
||||
|
||||
|
||||
|
||||
[SerializeField] float returnForce = 0.006f;
|
||||
[SerializeField] float impulsForce = 0.025f;
|
||||
[SerializeField] float maxRecoil = 0.1f;
|
||||
|
||||
private Animator anim;
|
||||
|
||||
Vector3 startPos,startRot;
|
||||
|
||||
float zOffset = 0f;
|
||||
float zVelocity = 0f;
|
||||
|
||||
int recoilCounter = 0;
|
||||
|
||||
//Has to be called once at the beginning and then again when switching guns
|
||||
public void OnSwitchWeapon(float fireRate)
|
||||
{
|
||||
//gun = newGun;
|
||||
anim = gun.GetComponent<Animator>();
|
||||
anim.SetFloat("ShootSpeed",1f/(60f/fireRate));
|
||||
startPos = gunPositionObj.transform.localPosition;
|
||||
startRot = gunRotationObj.transform.localRotation.eulerAngles;
|
||||
}
|
||||
|
||||
|
||||
public void recoil(float force)
|
||||
{
|
||||
//Play the animation
|
||||
anim.Play("Shoot");
|
||||
playerMouseLook.fullPitch -= cameraRecoilX * Mathf.PerlinNoise(Time.time * 3f + 10f, 1f);
|
||||
transform.Rotate(Vector3.up * ((Mathf.PerlinNoise(Time.time * 1f + 10f, 1f) - 0.5f) * 2f) * cameraRecoilY);
|
||||
//Add force for the recoil
|
||||
recoilCounter++;
|
||||
}
|
||||
|
||||
public void gunSideSwey(float sinVal,float moveInput)
|
||||
{
|
||||
|
||||
swey = (sweyMult * sinVal * moveInput * 0.7f
|
||||
+ sweyMult * sinVal * moveInput * ((Mathf.PerlinNoise(Time.time * 1f + 10f, 1f) - 0.5f) * 2f) * 0.3f) * Mathf.Clamp((1 - ADSController.aimVal) * (1 - ADSController.aimVal), sweyWhileAim,1f);
|
||||
|
||||
}
|
||||
|
||||
|
||||
void FixedUpdate()
|
||||
{
|
||||
//Apply recoil based on the number of shots fired
|
||||
for (int i = 0; i < recoilCounter; i++)
|
||||
{
|
||||
zVelocity -= impulsForce * 0.9f + impulsForce * 0.1f * Mathf.PerlinNoise(i,1f);
|
||||
}
|
||||
recoilCounter = 0;
|
||||
|
||||
|
||||
zOffset += zVelocity;
|
||||
|
||||
if (zOffset > 0)
|
||||
{
|
||||
zOffset = 0f;
|
||||
zVelocity = 0f;
|
||||
}
|
||||
else if (zOffset < 0)
|
||||
{
|
||||
zVelocity += returnForce * 0.9f + returnForce * 0.1f * Mathf.PerlinNoise(Time.time,1f);
|
||||
|
||||
}
|
||||
|
||||
zOffset = Mathf.Clamp(zOffset,-maxRecoil * 0.5f + -maxRecoil * 0.5f * Mathf.PerlinNoise(Time.time * 1000,1),0);
|
||||
|
||||
//Position recoil
|
||||
if (positionRecoil)
|
||||
{
|
||||
int sideLock = 0;
|
||||
|
||||
if (sideSwey) sideLock = 1;
|
||||
gunPositionObj.transform.localPosition = startPos + new Vector3(
|
||||
positionMultX * zOffset * ((Mathf.PerlinNoise(Time.time * 1f + 10f, 1f) - 0.5f) * 2f) + sideLock * swey,
|
||||
positionMultY * zOffset * Mathf.PerlinNoise(Time.time * 2f + 20f, 2f),
|
||||
positionMultZ* zOffset * ((Mathf.PerlinNoise(Time.time * 3f + 30f, 3f) - 0.5f) * 2f));
|
||||
}
|
||||
else
|
||||
{
|
||||
gunPositionObj.transform.localPosition = startPos;
|
||||
}
|
||||
|
||||
//Rotation recoil
|
||||
if (rotationRecoil)
|
||||
{
|
||||
int xLock = 0;
|
||||
int yLock = 0;
|
||||
int zLock = 0;
|
||||
|
||||
|
||||
if (rotX) xLock = 1;
|
||||
if (rotY) yLock = 1;
|
||||
if (rotZ) zLock = 1;
|
||||
|
||||
|
||||
gunRotationObj.transform.localRotation = Quaternion.Euler(
|
||||
startRot.x + xLock * rotationMultX * zOffset * Mathf.PerlinNoise(Time.time * 3f + 30f, 4f),
|
||||
startRot.y + yLock * rotationMultY * zOffset * ((Mathf.PerlinNoise(Time.time * 2f + 10f, 3f) - 0.5f) * 2f),
|
||||
startRot.z + zLock * rotationMultZ * zOffset * ((Mathf.PerlinNoise(Time.time * 1.5f, 2f) - 0.5f) * 2f));
|
||||
}
|
||||
else
|
||||
{
|
||||
gunRotationObj.transform.localRotation = Quaternion.Euler(startRot.x, startRot.y, startRot.z);
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
}
|
||||
@@ -1,11 +0,0 @@
|
||||
fileFormatVersion: 2
|
||||
guid: b366149a1bdd3ad4884ac2afe0fe11a1
|
||||
MonoImporter:
|
||||
externalObjects: {}
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
Reference in New Issue
Block a user