chore: Example Controllers Code Cleanup

This commit is contained in:
MrGadget 2024-08-06 23:36:55 -04:00
parent e21339240d
commit 96ba861e2c
6 changed files with 19 additions and 51 deletions

View File

@ -374,9 +374,6 @@ void HandleMouseSteer(float deltaTime)
// Apply rotation
transform.Rotate(0f, turnSpeed * deltaTime, 0f);
// Decay the accumulator over time
//float decayRate = 5f; // Adjust as needed
//mouseInputX = Mathf.MoveTowards(mouseInputX, 0f, decayRate * deltaTime);
mouseInputX = Mathf.MoveTowards(mouseInputX, 0f, mouseSensitivity * deltaTime);
}

View File

@ -93,6 +93,15 @@ public enum ControlOptions : byte
[Tooltip("Gravity factors into decelleration")]
public float inputGravity = 2f;
[Header("Turning")]
[Range(0, 300f)]
[Tooltip("Max Rotation in degrees per second")]
public float maxTurnSpeed = 100f;
[Range(0, 10f)]
[FormerlySerializedAs("turnDelta")]
[Tooltip("Rotation acceleration in degrees per second squared")]
public float turnAcceleration = 3f;
[Header("Jumping")]
[Range(0, 10f)]
[Tooltip("Initial jump speed in meters per second")]
@ -105,18 +114,6 @@ public enum ControlOptions : byte
[Tooltip("Jump acceleration in meters per second squared")]
public float jumpAcceleration = 4f;
[Header("Turning")]
[Range(0, 300f)]
[Tooltip("Max Rotation in degrees per second")]
public float maxTurnSpeed = 100f;
[Range(0, 10f)]
[FormerlySerializedAs("turnDelta")]
[Tooltip("Rotation acceleration in degrees per second squared")]
public float turnAcceleration = 3f;
//[Range(0, 10f)]
//[Tooltip("Sensitivity factors into accelleration")]
//public float mouseSensitivity = 2f;
[Header("Diagnostics")]
[ReadOnly, SerializeField]
GroundState groundState = GroundState.Grounded;
@ -319,9 +316,6 @@ void HandleMouseSteer(float deltaTime)
// Apply rotation
transform.Rotate(0f, turnSpeed * deltaTime, 0f);
// Decay the accumulator over time
//float decayRate = 5f; // Adjust as needed
//mouseInputX = Mathf.MoveTowards(mouseInputX, 0f, decayRate * deltaTime);
mouseInputX = Mathf.MoveTowards(mouseInputX, 0f, mouseSensitivity * deltaTime);
}

View File

@ -42,7 +42,6 @@ public enum ControlOptions : byte
[Header("Components")]
public BoxCollider boxCollider;
public CharacterController characterController;
public NetworkTransformReliable tankNTR;
[Header("User Interface")]
public GameObject ControllerUIPrefab;
@ -148,9 +147,6 @@ void Reset()
GetComponent<Rigidbody>().isKinematic = true;
tankNTR = GetComponent<NetworkTransformReliable>();
tankNTR.compressRotation = true;
#if UNITY_EDITOR
// For convenience in the examples, we use the GUID of the TankControllerUI prefab
// to find the correct prefab in the Mirror/Examples/_Common/Controllers folder.
@ -171,7 +167,6 @@ public override void OnStartAuthority()
{
// capsuleCollider and characterController are mutually exclusive
// Having both enabled would double fire triggers and other collisions
//boxCollider.enabled = false;
characterController.enabled = true;
this.enabled = true;
}
@ -182,7 +177,6 @@ public override void OnStopAuthority()
// capsuleCollider and characterController are mutually exclusive
// Having both enabled would double fire triggers and other collisions
//boxCollider.enabled = true;
characterController.enabled = false;
}

View File

@ -30,7 +30,7 @@ void OnHealthChanged(byte oldHealth, byte newHealth)
healthBar.color = Color.yellow;
if (newHealth < 2)
healthBar.color = Color.red;
if (newHealth <= 0)
if (newHealth < 1)
healthBar.color = Color.black;
}
@ -62,14 +62,15 @@ public override void OnStartServer()
public void TakeDamage(byte damage)
{
// Skip if health is already 0
if (health <= 0) return;
if (health == 0) return;
health -= damage;
if (health <= 0)
{
if (damage > health)
health = 0;
else
health -= damage;
if (health == 0)
{
if (connectionToClient != null)
Respawn.RespawnPlayer(respawn, respawnTime, connectionToClient);
else if (netIdentity.sceneId != 0)

View File

@ -141,9 +141,6 @@ void OnPlayerColorChanged(Color32 _, Color32 newColor)
#region Unity Callbacks
/// <summary>
/// Add your validation code here after the base.OnValidate(); call.
/// </summary>
protected override void OnValidate()
{
// Skip if Editor is in Play mode
@ -153,7 +150,6 @@ protected override void OnValidate()
Reset();
}
// NOTE: Do not put objects in DontDestroyOnLoad (DDOL) in Awake. You can do that in Start instead.
void Reset()
{
if (animator == null)
@ -195,7 +191,6 @@ Transform FindDeepChild(Transform aParent, string aName)
// The base Tank uses the first NetworkTransformReliable for the tank body
// Add additional NetworkTransformReliable components for the turret and barrel
// Set SyncPosition to false because we only want to sync rotation
NetworkTransformReliable[] NTRs = GetComponents<NetworkTransformReliable>();
if (NTRs.Length < 2)
@ -207,13 +202,8 @@ Transform FindDeepChild(Transform aParent, string aName)
else
turretNTR = NTRs[1];
// Ensure SyncDirection is Client to Server
turretNTR.syncDirection = SyncDirection.ClientToServer;
turretNTR.syncPosition = false;
turretNTR.compressRotation = true;
// Set SyncPosition to false because we only want to sync rotation
//turretNTR.syncPosition = false;
turretNTR.syncPosition = false;
if (turret != null)
turretNTR.target = turret;
@ -227,13 +217,8 @@ Transform FindDeepChild(Transform aParent, string aName)
else
barrelNTR = NTRs[2];
// Ensure SyncDirection is Client to Server
barrelNTR.syncDirection = SyncDirection.ClientToServer;
barrelNTR.syncPosition = false;
barrelNTR.compressRotation = true;
// Set SyncPosition to false because we only want to sync rotation
//barrelNTR.syncPosition = false;
barrelNTR.syncPosition = false;
if (barrel != null)
barrelNTR.target = barrel;
@ -334,9 +319,6 @@ void HandleMouseTurret(float deltaTime)
// Apply rotation
turret.Rotate(0f, turretSpeed * deltaTime, 0f);
// Decay the accumulator over time
//float decayRate = 5f; // Adjust as needed
//mouseInputX = Mathf.MoveTowards(mouseInputX, 0f, decayRate * deltaTime);
mouseInputX = Mathf.MoveTowards(mouseInputX, 0f, mouseSensitivity * deltaTime);
}

View File

@ -45,7 +45,7 @@ void Start()
Destroy(gameObject, destroyAfter);
}
private void OnCollisionEnter(Collision collision)
void OnCollisionEnter(Collision collision)
{
//Debug.Log($"Hit: {collision.gameObject}");