maint: renamed player folder to units to match namespaces. added unit class as well.
This commit is contained in:
@@ -30,23 +30,33 @@ public class UnitCombat : MonoBehaviour{
|
|||||||
|
|
||||||
// Update is called once per frame
|
// Update is called once per frame
|
||||||
void Update(){
|
void Update(){
|
||||||
|
DragAttackedUnits();
|
||||||
|
}
|
||||||
|
|
||||||
|
void DragAttackedUnits(){
|
||||||
|
// Get the original difference in position for speed and direction
|
||||||
positionDelta = Vector3.Lerp(positionDelta, lastPosition.DirectionTo(transform.position), 5f * Time.deltaTime);
|
positionDelta = Vector3.Lerp(positionDelta, lastPosition.DirectionTo(transform.position), 5f * Time.deltaTime);
|
||||||
speedDelta = Vector3.Distance(lastPosition, transform.position) / Time.deltaTime;
|
speedDelta = Vector3.Distance(lastPosition, transform.position) / Time.deltaTime;
|
||||||
|
|
||||||
|
// Add some randomness to the movements based on small offsets
|
||||||
float sinVal = Mathf.Sin(2f + sinOffset) * sinAmplitude;
|
float sinVal = Mathf.Sin(2f + sinOffset) * sinAmplitude;
|
||||||
speedDelta += sinVal;
|
speedDelta += sinVal;
|
||||||
|
|
||||||
// Test
|
// Set a floor to prevent them from not moving enough
|
||||||
speedDelta *= 1.0f;
|
|
||||||
speedDelta = Mathf.Max(3f, speedDelta);
|
speedDelta = Mathf.Max(3f, speedDelta);
|
||||||
|
|
||||||
|
// Multiply the speed to be lower when further, and faster when close
|
||||||
float speedDiff = Mathf.Lerp(.2f, 1.4f, speedDelta);
|
float speedDiff = Mathf.Lerp(.2f, 1.4f, speedDelta);
|
||||||
speedDelta *= speedDiff;
|
speedDelta *= speedDiff;
|
||||||
|
|
||||||
|
// Debug
|
||||||
DebugOverlayDrawer.ChangeValue($"Combat - {name}", "Position Delta", positionDelta);
|
DebugOverlayDrawer.ChangeValue($"Combat - {name}", "Position Delta", positionDelta);
|
||||||
DebugOverlayDrawer.ChangeValue($"Combat - {name}", "Speed Delta", speedDelta);
|
DebugOverlayDrawer.ChangeValue($"Combat - {name}", "Speed Delta", speedDelta);
|
||||||
|
|
||||||
|
// Update last known position
|
||||||
lastPosition = transform.position;
|
lastPosition = transform.position;
|
||||||
|
|
||||||
|
// Apply the speed, direction, and rotation to each unit
|
||||||
foreach (Collider draggedUnit in draggedUnits) {
|
foreach (Collider draggedUnit in draggedUnits) {
|
||||||
UnitMovementHandler draggedUnitMovement = draggedUnit.GetComponent<UnitMovementHandler>();
|
UnitMovementHandler draggedUnitMovement = draggedUnit.GetComponent<UnitMovementHandler>();
|
||||||
if (!draggedUnitMovement) {
|
if (!draggedUnitMovement) {
|
||||||
@@ -10,9 +10,8 @@ using Sirenix.OdinInspector;
|
|||||||
using Sirenix.Serialization;
|
using Sirenix.Serialization;
|
||||||
using Unity.Netcode;
|
using Unity.Netcode;
|
||||||
|
|
||||||
public class Player : NetworkBehaviour, IKillable{
|
public class Player : Unit, IKillable{
|
||||||
[HideInInspector] public PlayerControls controls;
|
[HideInInspector] public PlayerControls controls;
|
||||||
[HideInInspector] public PlayerCamera camera;
|
|
||||||
|
|
||||||
float IKillable.maxHealth{ get; set; }
|
float IKillable.maxHealth{ get; set; }
|
||||||
float IKillable.currentHealth{ get; set; }
|
float IKillable.currentHealth{ get; set; }
|
||||||
@@ -89,4 +88,4 @@ public class Player : NetworkBehaviour, IKillable{
|
|||||||
throw new NotImplementedException();
|
throw new NotImplementedException();
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
4
Assets/Scripts/Units/Unit.cs
Normal file
4
Assets/Scripts/Units/Unit.cs
Normal file
@@ -0,0 +1,4 @@
|
|||||||
|
using Unity.Netcode;
|
||||||
|
|
||||||
|
public class Unit : NetworkBehaviour{
|
||||||
|
}
|
||||||
3
Assets/Scripts/Units/Unit.cs.meta
Normal file
3
Assets/Scripts/Units/Unit.cs.meta
Normal file
@@ -0,0 +1,3 @@
|
|||||||
|
fileFormatVersion: 2
|
||||||
|
guid: d9f5c0c9bf384882925c15b3c93fff1b
|
||||||
|
timeCreated: 1759554015
|
||||||
Reference in New Issue
Block a user