fixed: all moving conditions working. removed 'moveFacing' primarily

This commit is contained in:
Chris
2025-08-10 12:24:41 -04:00
parent 8652a2d2d8
commit a9f51b62c0

View File

@@ -9,7 +9,8 @@ public enum PlayerFacingDirection{
TowardsTarget = 0,
MatchForward,
MatchCamera,
Static
Static,
Momentum
}
namespace Reset.Units{
@@ -19,9 +20,6 @@ namespace Reset.Units{
// }
public class UnitMovementData{
// Movement Direction
public Vector3 targetMoveDirection;
public PlayerFacingDirection moveFacing;
public float accelerationSmoothing = 5f;
public float deaccelerationSmoothing = 5f;
public AnimationCurve deaccelerationCurve;
@@ -77,15 +75,11 @@ namespace Reset.Units{
UpdateCurrentSpeed();
UpdateCurrentGravity();
UpdateCurrentRotation();
//
DoMovement();
}
private void UpdateCurrentDirection(){
// Construct move direction
Vector3 targetDirection = data.targetMoveDirection;
Debug.Log(controls);
// Get input value
Vector3 inputMovement =
new Vector3(
@@ -95,26 +89,11 @@ namespace Reset.Units{
controls.
rawMoveInput.y);
if (inputMovement.magnitude < .1f) {
inputMovement = Vector3.zero;
}
// Construct move direction
Vector3 targetDirection = inputMovement;
// Change how movement is managed based on facing state
switch (data.moveFacing) {
case PlayerFacingDirection.TowardsTarget:
break;
case PlayerFacingDirection.MatchForward: // TODO: Recomment
// targetDirection = agent.transform.forward * inputMovement.magnitude;
targetDirection = inputMovement;
break;
case PlayerFacingDirection.MatchCamera:
targetDirection = Quaternion.Euler(Camera.main.transform.forward.DirectionTo(transform.forward)) * inputMovement; // NOTE: This used to be t: currentRotSpeed * Time.deltaTime.
// See how it feels with a hard set value and go fro there.
break;
case PlayerFacingDirection.Static:
break;
default:
throw new ArgumentOutOfRangeException();
if (inputMovement.magnitude < .1f) {
targetDirection = Vector3.zero;
}
// Remove Y from variables
@@ -123,7 +102,7 @@ namespace Reset.Units{
// Smooth movement
if (targetNoY.magnitude > currentNoY.magnitude) {
currentNoY = Vector3.Lerp(currentNoY, targetNoY,data.accelerationSmoothing * Time.deltaTime);
currentNoY = Vector3.Slerp(currentNoY, targetNoY,data.accelerationSmoothing * Time.deltaTime);
} else {
float deaccelValue = data.deaccelerationCurve.Evaluate(inputMovement.magnitude);
@@ -164,22 +143,22 @@ namespace Reset.Units{
Vector3 inputMovement = new Vector3(controls.rawMoveInput.x, 0f, controls.rawMoveInput.y);
switch (data.rotateFacing) {
// TODO: Recomment
case PlayerFacingDirection.TowardsTarget:
// Set rotation to just the direction of the target
Debug.LogError("Not implemented...");
break;
case PlayerFacingDirection.Momentum:
if (inputMovement.magnitude > .03f){
outputRotation = Camera.main.transform.rotation * Quaternion.LookRotation(outputMoveDirection);
}
break;
case PlayerFacingDirection.MatchForward:
if (controls.rawMoveInput.magnitude < 0.01f) { break; }
outputRotation = Quaternion.LookRotation(inputMovement) *
Quaternion.Euler(Camera.main.transform.rotation.eulerAngles.Flatten(0f, null, 0f));
outputRotation = Camera.main.transform.rotation * Quaternion.LookRotation(inputMovement);
break;
case PlayerFacingDirection.MatchCamera:
// Craft a new rotation that flattens the camera's rotation to the ground
// Needed to keep the character from inheriting the camera's height-rotation
outputRotation = Quaternion.Euler(Camera.main.transform.rotation.eulerAngles.Flatten(0, null, 0));
break;
case PlayerFacingDirection.Static:
@@ -196,7 +175,7 @@ namespace Reset.Units{
}
public void DoMovement(Vector3 moveDir, float speed){
Debug.Log( outputMoveDirection);;
// Commit the move, with respect to the camera's rotation
controller.Move((Camera.main.transform.rotation.Flatten(0, null, 0) * (moveDir * speed) * Time.deltaTime));
}