mirror of
https://github.com/DerTyp7/defrain-shooter-unity.git
synced 2025-10-29 20:52:10 +01:00
Headbob
-Added Headbob
This commit is contained in:
48
Assets/Scripts/Player/Headbob.cs
Normal file
48
Assets/Scripts/Player/Headbob.cs
Normal file
@@ -0,0 +1,48 @@
|
||||
using System.Collections;
|
||||
using System.Collections.Generic;
|
||||
using UnityEngine;
|
||||
using Mirror;
|
||||
public class Headbob : NetworkBehaviour
|
||||
{
|
||||
[SerializeField] private float posCheckDistance = 0.01f;
|
||||
[SerializeField] private float checkDist = 0.0f;
|
||||
|
||||
[Header("Step Settings")]
|
||||
[SerializeField] private float stepAmplitude;
|
||||
[SerializeField] private float stepFrequency;
|
||||
[SerializeField] private Transform Neck;
|
||||
|
||||
private Vector3 lastPos;
|
||||
private float oldDist = 0;
|
||||
private void Start()
|
||||
{
|
||||
lastPos = this.transform.position;
|
||||
}
|
||||
|
||||
private void Update()
|
||||
{
|
||||
float dist = Vector3.Distance(lastPos, this.transform.position);
|
||||
|
||||
|
||||
if (dist > posCheckDistance)
|
||||
{
|
||||
checkDist += dist - oldDist;
|
||||
lastPos = this.transform.position;
|
||||
oldDist = dist;
|
||||
}
|
||||
if (checkDist > 2)
|
||||
{
|
||||
checkDist = 0;
|
||||
}
|
||||
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);
|
||||
}
|
||||
|
||||
}
|
||||
11
Assets/Scripts/Player/Headbob.cs.meta
Normal file
11
Assets/Scripts/Player/Headbob.cs.meta
Normal file
@@ -0,0 +1,11 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 4db7caf602ce379408a59c8722e06e46
|
||||
MonoImporter:
|
||||
externalObjects: {}
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
@@ -5,23 +5,33 @@ using Mirror;
|
||||
|
||||
public class Player : NetworkBehaviour
|
||||
{
|
||||
public bool isAlive;
|
||||
public bool isAlive = true;
|
||||
public Team team;
|
||||
[SerializeField] private const int defaultHp = 100;
|
||||
|
||||
|
||||
public ulong clientId;
|
||||
|
||||
[SyncVar(hook = nameof(SetName))]
|
||||
[SyncVar(hook = nameof(SetName))]
|
||||
public string username;
|
||||
|
||||
[SerializeField] GameObject usernameTextObj;
|
||||
|
||||
private int health;
|
||||
[SerializeField] [SyncVar]public int health = 100;
|
||||
private int kills;
|
||||
private int deaths;
|
||||
|
||||
private void Start()
|
||||
{
|
||||
if (isServer)
|
||||
{
|
||||
health = defaultHp;
|
||||
}
|
||||
}
|
||||
public override void OnStartLocalPlayer()
|
||||
{
|
||||
base.OnStartClient();
|
||||
|
||||
}
|
||||
|
||||
public void SetName(string oldName, string newName)
|
||||
@@ -56,8 +66,11 @@ public class Player : NetworkBehaviour
|
||||
}
|
||||
public void RemoveHealth(int value)
|
||||
{
|
||||
|
||||
|
||||
if (isAlive)
|
||||
{
|
||||
Debug.Log("yeet" + value);
|
||||
health -= value;
|
||||
if (health <= 0)
|
||||
{
|
||||
|
||||
@@ -81,7 +81,6 @@ public class PlayerController : NetworkBehaviour
|
||||
}
|
||||
|
||||
groundAngle = Vector3.Angle(hit.normal,transform.up);
|
||||
Debug.Log(moveGroundAngle);
|
||||
}
|
||||
}
|
||||
private void OnDrawGizmos()
|
||||
@@ -101,7 +100,7 @@ public class PlayerController : NetworkBehaviour
|
||||
if (Input.GetButtonDown("Jump") && isGrounded)
|
||||
{
|
||||
//Debug.Log("Jump");
|
||||
velocityY += Mathf.Sqrt(jumpHeight * 4f);
|
||||
velocityY += Mathf.Sqrt(jumpHeight * -2f * gravity);
|
||||
}
|
||||
|
||||
inputDirection = new Vector3(Input.GetAxisRaw("Horizontal"),0, Input.GetAxisRaw("Vertical")); //Get Inputs
|
||||
|
||||
@@ -37,6 +37,7 @@ public class PlayerMouseLook : NetworkBehaviour
|
||||
|
||||
playerCamera.gameObject.SetActive(true);
|
||||
|
||||
|
||||
if (lockCursor)
|
||||
{
|
||||
Cursor.lockState = CursorLockMode.Locked;
|
||||
|
||||
Reference in New Issue
Block a user