mirror of
https://github.com/DerTyp7/defrain-shooter-unity.git
synced 2025-10-29 20:52:10 +01:00
Camera recoil
This commit is contained in:
@@ -5,7 +5,7 @@ using UnityEngine;
|
||||
public class AimDownSights : MonoBehaviour
|
||||
{
|
||||
[SerializeField] float aimSpeed = 0.01f;
|
||||
[SerializeField][Range(0,1)] float aimVal = 0;
|
||||
[SerializeField][Range(0,1)] public float aimVal = 0;
|
||||
[SerializeField] private GameObject gun;
|
||||
[SerializeField] GameObject AimPoint;
|
||||
[SerializeField] GameObject HoldPoint;
|
||||
@@ -15,9 +15,8 @@ public class AimDownSights : MonoBehaviour
|
||||
|
||||
return true;
|
||||
}
|
||||
private void Update()
|
||||
private void FixedUpdate()
|
||||
{
|
||||
Debug.Log(Input.GetButton("Aim"));
|
||||
if (Input.GetButton("Aim"))
|
||||
{
|
||||
isAiming = true;
|
||||
@@ -29,7 +28,7 @@ public class AimDownSights : MonoBehaviour
|
||||
aimVal -= aimSpeed;
|
||||
}
|
||||
aimVal = Mathf.Clamp(aimVal,0,1);
|
||||
|
||||
gun.transform.position = Vector3.Lerp(HoldPoint.transform.position, AimPoint.transform.position, aimVal);
|
||||
|
||||
gun.transform.position = Vector3.Lerp(HoldPoint.transform.position, AimPoint.transform.position,Mathf.Pow(aimVal,1.3f)) ;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -5,6 +5,7 @@ using Mirror;
|
||||
public class Headbob : NetworkBehaviour
|
||||
{
|
||||
[SerializeField] private PlayerController playerController;
|
||||
[SerializeField] private ShootAnimation gunAnimation;
|
||||
|
||||
|
||||
[SerializeField] private float posCheckDistance = 0.01f;
|
||||
@@ -22,6 +23,14 @@ public class Headbob : NetworkBehaviour
|
||||
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;
|
||||
@@ -50,6 +59,7 @@ public class Headbob : NetworkBehaviour
|
||||
{
|
||||
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;
|
||||
}
|
||||
|
||||
@@ -8,15 +8,16 @@ using Mirror;
|
||||
|
||||
public class PlayerController : NetworkBehaviour
|
||||
{
|
||||
|
||||
[SerializeField] private AimDownSights ADSContoller;
|
||||
[Header("Movement")]
|
||||
[SerializeField] private float walkSpeed = 6.0f;
|
||||
[SerializeField] private float sprintSpeed = 10.0f;
|
||||
[SerializeField] private float aimWalkSpeed = 3.0f;
|
||||
|
||||
[SerializeField][Range(0.0f, 0.5f)] private float moveSmoothTime = 0.001f;
|
||||
[SerializeField] float gravity = -10.0f;
|
||||
[SerializeField] private float jumpHeight;
|
||||
private Vector3 inputDirection = Vector3.zero;
|
||||
public Vector3 inputDirection = Vector3.zero;
|
||||
private Vector3 moveDirection;
|
||||
|
||||
[Header("Ground Check")]
|
||||
@@ -100,15 +101,15 @@ public class PlayerController : NetworkBehaviour
|
||||
{
|
||||
|
||||
|
||||
if (Input.GetAxisRaw("Sprint") > 0 && isGrounded)
|
||||
if (Input.GetAxisRaw("Sprint") > 0 && isGrounded && !ADSContoller.isAiming)
|
||||
{
|
||||
//Debug.Log("Sprint");
|
||||
movementSpeed = sprintSpeed;
|
||||
isSprinting = true;
|
||||
}
|
||||
else
|
||||
{
|
||||
movementSpeed = walkSpeed;
|
||||
if(ADSContoller.isAiming) movementSpeed = aimWalkSpeed;
|
||||
else movementSpeed = walkSpeed;
|
||||
isSprinting = false;
|
||||
}
|
||||
|
||||
|
||||
@@ -18,7 +18,7 @@ public class PlayerMouseLook : NetworkBehaviour
|
||||
[SerializeField] [Range(0.0f, 0.5f)] private float mouseSmoothTime = 0.001f;
|
||||
[SerializeField] private bool lockCursor = true;
|
||||
|
||||
private float fullPitch = 0f;
|
||||
public float fullPitch = 0f;
|
||||
private float cameraPitch = 0f;
|
||||
private float neckPitch = 0f;
|
||||
private float velocityY = 0.0f;
|
||||
|
||||
Reference in New Issue
Block a user