-Added Headbob
This commit is contained in:
juliuse98
2021-11-04 08:15:48 +01:00
parent 0e780162db
commit 312b51656b
9 changed files with 361 additions and 14 deletions

View 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);
}
}

View File

@@ -0,0 +1,11 @@
fileFormatVersion: 2
guid: 4db7caf602ce379408a59c8722e06e46
MonoImporter:
externalObjects: {}
serializedVersion: 2
defaultReferences: []
executionOrder: 0
icon: {instanceID: 0}
userData:
assetBundleName:
assetBundleVariant:

View File

@@ -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)
{

View File

@@ -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

View File

@@ -37,6 +37,7 @@ public class PlayerMouseLook : NetworkBehaviour
playerCamera.gameObject.SetActive(true);
if (lockCursor)
{
Cursor.lockState = CursorLockMode.Locked;