mirror of
https://github.com/DerTyp7/defrain-shooter-unity.git
synced 2025-10-29 20:52:10 +01:00
Added Stuff
This commit is contained in:
@@ -4,16 +4,23 @@ 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 stepAmplitude;
|
||||
[SerializeField] private float stepFrequency;
|
||||
[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 newPos;
|
||||
private float oldDist = 0;
|
||||
private float lerpVal = 0;
|
||||
private void Start()
|
||||
{
|
||||
lastPos = this.transform.position;
|
||||
@@ -21,28 +28,51 @@ public class Headbob : NetworkBehaviour
|
||||
|
||||
private void Update()
|
||||
{
|
||||
float dist = Vector3.Distance(lastPos, this.transform.position);
|
||||
|
||||
|
||||
if (dist > posCheckDistance)
|
||||
float amplitude;
|
||||
if (playerController.isGrounded)
|
||||
{
|
||||
checkDist += dist - oldDist;
|
||||
lastPos = this.transform.position;
|
||||
oldDist = dist;
|
||||
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;
|
||||
}
|
||||
if (checkDist > 2)
|
||||
else
|
||||
{
|
||||
checkDist = 0;
|
||||
Neck.localPosition = Vector3.zero;
|
||||
if (false) {
|
||||
Neck.localPosition = Vector3.Lerp(newPos, Vector3.zero, lerpVal);
|
||||
if (lerpVal < 1)
|
||||
{
|
||||
lerpVal = lerpVal + 0.01f;
|
||||
}
|
||||
else
|
||||
{
|
||||
Neck.position = Vector3.zero;
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
Vector3 newPos = new Vector3(Neck.transform.position.x,getSin(stepAmplitude,stepAmplitude,checkDist),Neck.transform.position.z);
|
||||
Neck.position = newPos;
|
||||
Debug.Log("Distance: " + checkDist + ", Sin " + getSin(stepAmplitude, stepAmplitude, checkDist));
|
||||
|
||||
}
|
||||
|
||||
private float getSin(float multiplier, float devisor,float x)
|
||||
{
|
||||
return multiplier * Mathf.Sin((x/Mathf.PI)*10);
|
||||
return multiplier * Mathf.Sin((x/3.14f) * 10 * devisor);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -28,6 +28,7 @@ public class PlayerController : NetworkBehaviour
|
||||
[SerializeField] private float moveGroundAngle;
|
||||
|
||||
public bool isGrounded;
|
||||
public bool isSprinting;
|
||||
private float movementSpeed;
|
||||
private float velocityY = 0.0f;
|
||||
private CharacterController controller;
|
||||
@@ -103,15 +104,23 @@ public class PlayerController : NetworkBehaviour
|
||||
{
|
||||
Debug.Log("Sprint");
|
||||
movementSpeed = sprintSpeed;
|
||||
isSprinting = true;
|
||||
}
|
||||
else
|
||||
{
|
||||
movementSpeed = walkSpeed;
|
||||
isSprinting = false;
|
||||
}
|
||||
|
||||
Debug.Log("ggg");
|
||||
//Grounded
|
||||
velocityY += gravity * Time.deltaTime;
|
||||
if (velocityY < 0)
|
||||
{
|
||||
velocityY += gravity * Time.deltaTime;
|
||||
}
|
||||
else
|
||||
{
|
||||
velocityY += gravity * 1.0f * Time.deltaTime;
|
||||
}
|
||||
if (isGrounded && velocityY < 0)
|
||||
velocityY = 0.0f;
|
||||
|
||||
@@ -135,8 +144,7 @@ public class PlayerController : NetworkBehaviour
|
||||
currentDir = moveDirection;
|
||||
}
|
||||
|
||||
currentDir = currentDir + new Vector3(0, velocityY, 0);
|
||||
velocity = currentDir * movementSpeed;
|
||||
velocity = currentDir * movementSpeed + new Vector3(0, velocityY, 0);
|
||||
|
||||
|
||||
controller.Move(velocity * Time.deltaTime);
|
||||
|
||||
@@ -14,7 +14,7 @@ public class PlayerMouseLook : NetworkBehaviour
|
||||
[SerializeField] private float neckStartAngle = 0f;
|
||||
[SerializeField] private float minCameraAngle = -90f;
|
||||
|
||||
[SerializeField] private float neckLength = 0.2f;
|
||||
private float neckLength = 0.2f;
|
||||
[SerializeField] [Range(0.0f, 0.5f)] private float mouseSmoothTime = 0.001f;
|
||||
[SerializeField] private bool lockCursor = true;
|
||||
|
||||
@@ -36,7 +36,7 @@ public class PlayerMouseLook : NetworkBehaviour
|
||||
controller = GetComponent<CharacterController>();
|
||||
|
||||
playerCamera.gameObject.SetActive(true);
|
||||
|
||||
neckLength = Vector3.Distance(playerNeck.position,playerCamera.position);
|
||||
|
||||
if (lockCursor)
|
||||
{
|
||||
|
||||
Reference in New Issue
Block a user