mirror of
https://github.com/DerTyp7/defrain-shooter-unity.git
synced 2025-10-29 20:52:10 +01:00
Oh Shit
This commit is contained in:
70
Assets/Scripts/Player/Headbob.cs
Normal file
70
Assets/Scripts/Player/Headbob.cs
Normal file
@@ -0,0 +1,70 @@
|
||||
using System.Collections;
|
||||
using System.Collections.Generic;
|
||||
using UnityEngine;
|
||||
using Mirror;
|
||||
public class Headbob : NetworkBehaviour
|
||||
{
|
||||
[SerializeField] private PlayerController playerController;
|
||||
|
||||
|
||||
[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 startPos;
|
||||
private Vector3 lastPos;
|
||||
private Vector3 newPos;
|
||||
private float oldDist = 0;
|
||||
private float lerpVal = 0;
|
||||
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;
|
||||
}
|
||||
newPos = new Vector3(getSin(amplitude / 2, stepFrequency, checkDist), getSin(amplitude, stepFrequency, checkDist), 0);
|
||||
Neck.localPosition = newPos;
|
||||
}
|
||||
else
|
||||
{
|
||||
Neck.localPosition = startPos;
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
private float getSin(float multiplier, float devisor,float x)
|
||||
{
|
||||
return multiplier * Mathf.Sin((x/3.14f) * 10 * devisor);
|
||||
}
|
||||
|
||||
}
|
||||
@@ -32,12 +32,28 @@ public class PlayerController : NetworkBehaviour
|
||||
[SerializeField] private float groundDistance = 0.4f;
|
||||
[SerializeField] private LayerMask groundMask;
|
||||
|
||||
<<<<<<< Updated upstream
|
||||
=======
|
||||
[Header("Ground Angle")]
|
||||
[SerializeField] private float groundAngle;
|
||||
[SerializeField] private float moveGroundAngle;
|
||||
|
||||
[Header("bullets per minute")]
|
||||
[SerializeField] private float bulletsPerMinute = 120f;
|
||||
[SerializeField] private bool canFire = true;
|
||||
|
||||
|
||||
|
||||
[SerializeField] private GameObject gun;
|
||||
|
||||
>>>>>>> Stashed changes
|
||||
public bool isGrounded;
|
||||
private float fullPitch = 0f;
|
||||
private float cameraPitch = 0f;
|
||||
private float neckPitch = 0f;
|
||||
private float velocityY = 0.0f;
|
||||
private CharacterController controller;
|
||||
[SerializeField]private Animator anim;
|
||||
|
||||
private Vector2 currentDir = Vector2.zero;
|
||||
private Vector2 currentDirVelocity = Vector2.zero;
|
||||
@@ -48,6 +64,7 @@ public class PlayerController : NetworkBehaviour
|
||||
|
||||
private void Start()
|
||||
{
|
||||
anim = gun.GetComponent<Animator>();
|
||||
if (isLocalPlayer)
|
||||
{
|
||||
controller = GetComponent<CharacterController>();
|
||||
@@ -93,6 +110,7 @@ public class PlayerController : NetworkBehaviour
|
||||
playerCamera.localEulerAngles = Vector3.right * fullPitch;
|
||||
|
||||
|
||||
<<<<<<< Updated upstream
|
||||
}
|
||||
playerCamera.position = playerNeck.position;
|
||||
playerCamera.position += playerNeck.up * neckLength;
|
||||
@@ -101,6 +119,59 @@ public class PlayerController : NetworkBehaviour
|
||||
}
|
||||
private void UpdateMovement()
|
||||
{
|
||||
=======
|
||||
IEnumerator OnGunReset()
|
||||
{
|
||||
//gun.GetComponent<Animator>().SetTrigger("shootTrigger");
|
||||
//gun.GetComponent<Animator>().Play("Shoot");
|
||||
anim.Play("Shoot");
|
||||
yield return new WaitForSeconds(anim.GetCurrentAnimatorStateInfo(0).normalizedTime);
|
||||
Debug.Log(anim.GetCurrentAnimatorStateInfo(0).speed);
|
||||
//Debug.Log(anim.GetNextAnimatorStateInfo(0).speed);
|
||||
|
||||
yield return new WaitForSeconds(0.5f/3f);
|
||||
|
||||
canFire = true;
|
||||
}
|
||||
IEnumerator reset()
|
||||
{
|
||||
yield return new WaitForSeconds(60f / bulletsPerMinute);
|
||||
Debug.Log(60f / bulletsPerMinute);
|
||||
canFire = true;
|
||||
}
|
||||
|
||||
|
||||
private void UpdateMovement()
|
||||
{
|
||||
|
||||
|
||||
if (Input.GetButton("Fire1") && canFire)
|
||||
{
|
||||
|
||||
canFire = false;
|
||||
anim.PlayInFixedTime("Base Layer.Shoot", 0, bulletsPerMinute);
|
||||
StartCoroutine("reset");
|
||||
//StartCoroutine("OnGunReset");
|
||||
//Debug.Log(anim.GetCurrentAnimatorStateInfo(0).speed);
|
||||
//Debug.Log(anim.GetCurrentAnimatorClipInfo(0).Length);
|
||||
//Debug.Log("mult " + anim.GetNextAnimatorStateInfo(0).speedMultiplier);
|
||||
|
||||
|
||||
}
|
||||
// Debug.Log("2 " + canFire);
|
||||
if (Input.GetAxisRaw("Sprint") > 0 && isGrounded)
|
||||
{
|
||||
Debug.Log("Sprint");
|
||||
movementSpeed = sprintSpeed;
|
||||
isSprinting = true;
|
||||
}
|
||||
else
|
||||
{
|
||||
movementSpeed = walkSpeed;
|
||||
isSprinting = false;
|
||||
}
|
||||
|
||||
>>>>>>> Stashed changes
|
||||
//Grounded
|
||||
velocityY += gravity * Time.deltaTime;
|
||||
if (isGrounded && velocityY < 0)
|
||||
|
||||
84
Assets/Scripts/Player/PlayerMouseLook.cs
Normal file
84
Assets/Scripts/Player/PlayerMouseLook.cs
Normal file
@@ -0,0 +1,84 @@
|
||||
using System.Collections;
|
||||
using System.Collections.Generic;
|
||||
using UnityEngine;
|
||||
using Mirror;
|
||||
|
||||
public class PlayerMouseLook : NetworkBehaviour
|
||||
{
|
||||
[Header("Mouse Look")]
|
||||
[SerializeField] private Transform playerCamera = null;
|
||||
[SerializeField] private Transform playerNeck = null;
|
||||
[SerializeField] private float mouseSensitivity = 4.0f;
|
||||
|
||||
[SerializeField] private float maxCameraAngle = 90f;
|
||||
[SerializeField] private float neckStartAngle = 0f;
|
||||
[SerializeField] private float minCameraAngle = -90f;
|
||||
|
||||
private float neckLength = 0.2f;
|
||||
[SerializeField] [Range(0.0f, 0.5f)] private float mouseSmoothTime = 0.001f;
|
||||
[SerializeField] private bool lockCursor = true;
|
||||
|
||||
private float fullPitch = 0f;
|
||||
private float cameraPitch = 0f;
|
||||
private float neckPitch = 0f;
|
||||
private float velocityY = 0.0f;
|
||||
private CharacterController controller;
|
||||
|
||||
private Vector2 currentMouseDelta = Vector2.zero;
|
||||
private Vector2 currentMouseDeltaVelocity = Vector2.zero;
|
||||
|
||||
|
||||
|
||||
private void Start()
|
||||
{
|
||||
if (isLocalPlayer)
|
||||
{
|
||||
controller = GetComponent<CharacterController>();
|
||||
|
||||
playerCamera.gameObject.SetActive(true);
|
||||
neckLength = Vector3.Distance(playerNeck.position,playerCamera.position);
|
||||
|
||||
if (lockCursor)
|
||||
{
|
||||
Cursor.lockState = CursorLockMode.Locked;
|
||||
Cursor.visible = false;
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
private void Update()
|
||||
{
|
||||
if (isLocalPlayer)
|
||||
{
|
||||
UpdateMouseLook();
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
private void UpdateMouseLook()
|
||||
{
|
||||
Vector2 targetMouseDelta = new Vector2(Input.GetAxis("Mouse X"), Input.GetAxis("Mouse Y")); //Get the axis of the mouse
|
||||
|
||||
currentMouseDelta = Vector2.SmoothDamp(currentMouseDelta, targetMouseDelta, ref currentMouseDeltaVelocity, mouseSmoothTime);
|
||||
fullPitch -= currentMouseDelta.y * mouseSensitivity;
|
||||
fullPitch = Mathf.Clamp(fullPitch, -maxCameraAngle, -minCameraAngle);
|
||||
|
||||
if (fullPitch >= neckStartAngle)
|
||||
{
|
||||
playerNeck.localEulerAngles = Vector3.right * (fullPitch - neckStartAngle);
|
||||
|
||||
}
|
||||
else
|
||||
{
|
||||
playerNeck.localEulerAngles = Vector3.right * 0f;
|
||||
playerCamera.localEulerAngles = Vector3.right * fullPitch;
|
||||
|
||||
|
||||
}
|
||||
playerCamera.position = playerNeck.position;
|
||||
playerCamera.position += playerNeck.up * neckLength;
|
||||
|
||||
transform.Rotate(Vector3.up * currentMouseDelta.x * mouseSensitivity); //Rotate the hole player if looked sideways (Rotates the player left and right)
|
||||
}
|
||||
|
||||
}
|
||||
18
Assets/Scripts/Weapons/ShootAnimation.cs
Normal file
18
Assets/Scripts/Weapons/ShootAnimation.cs
Normal file
@@ -0,0 +1,18 @@
|
||||
using System.Collections;
|
||||
using System.Collections.Generic;
|
||||
using UnityEngine;
|
||||
|
||||
public class ShootAnimation : MonoBehaviour
|
||||
{
|
||||
// Start is called before the first frame update
|
||||
void Start()
|
||||
{
|
||||
|
||||
}
|
||||
|
||||
// Update is called once per frame
|
||||
void Update()
|
||||
{
|
||||
|
||||
}
|
||||
}
|
||||
11
Assets/Scripts/Weapons/ShootAnimation.cs.meta
Normal file
11
Assets/Scripts/Weapons/ShootAnimation.cs.meta
Normal file
@@ -0,0 +1,11 @@
|
||||
fileFormatVersion: 2
|
||||
guid: b366149a1bdd3ad4884ac2afe0fe11a1
|
||||
MonoImporter:
|
||||
externalObjects: {}
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
Reference in New Issue
Block a user