fixed: all moving conditions working. removed 'moveFacing' primarily
This commit is contained in:
@@ -9,7 +9,8 @@ public enum PlayerFacingDirection{
|
|||||||
TowardsTarget = 0,
|
TowardsTarget = 0,
|
||||||
MatchForward,
|
MatchForward,
|
||||||
MatchCamera,
|
MatchCamera,
|
||||||
Static
|
Static,
|
||||||
|
Momentum
|
||||||
}
|
}
|
||||||
|
|
||||||
namespace Reset.Units{
|
namespace Reset.Units{
|
||||||
@@ -19,9 +20,6 @@ namespace Reset.Units{
|
|||||||
// }
|
// }
|
||||||
public class UnitMovementData{
|
public class UnitMovementData{
|
||||||
// Movement Direction
|
// Movement Direction
|
||||||
public Vector3 targetMoveDirection;
|
|
||||||
public PlayerFacingDirection moveFacing;
|
|
||||||
|
|
||||||
public float accelerationSmoothing = 5f;
|
public float accelerationSmoothing = 5f;
|
||||||
public float deaccelerationSmoothing = 5f;
|
public float deaccelerationSmoothing = 5f;
|
||||||
public AnimationCurve deaccelerationCurve;
|
public AnimationCurve deaccelerationCurve;
|
||||||
@@ -77,15 +75,11 @@ namespace Reset.Units{
|
|||||||
UpdateCurrentSpeed();
|
UpdateCurrentSpeed();
|
||||||
UpdateCurrentGravity();
|
UpdateCurrentGravity();
|
||||||
UpdateCurrentRotation();
|
UpdateCurrentRotation();
|
||||||
//
|
|
||||||
DoMovement();
|
DoMovement();
|
||||||
}
|
}
|
||||||
|
|
||||||
private void UpdateCurrentDirection(){
|
private void UpdateCurrentDirection(){
|
||||||
// Construct move direction
|
|
||||||
Vector3 targetDirection = data.targetMoveDirection;
|
|
||||||
|
|
||||||
Debug.Log(controls);
|
|
||||||
// Get input value
|
// Get input value
|
||||||
Vector3 inputMovement =
|
Vector3 inputMovement =
|
||||||
new Vector3(
|
new Vector3(
|
||||||
@@ -95,26 +89,11 @@ namespace Reset.Units{
|
|||||||
controls.
|
controls.
|
||||||
rawMoveInput.y);
|
rawMoveInput.y);
|
||||||
|
|
||||||
if (inputMovement.magnitude < .1f) {
|
// Construct move direction
|
||||||
inputMovement = Vector3.zero;
|
Vector3 targetDirection = inputMovement;
|
||||||
}
|
|
||||||
|
|
||||||
// Change how movement is managed based on facing state
|
if (inputMovement.magnitude < .1f) {
|
||||||
switch (data.moveFacing) {
|
targetDirection = Vector3.zero;
|
||||||
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();
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// Remove Y from variables
|
// Remove Y from variables
|
||||||
@@ -123,7 +102,7 @@ namespace Reset.Units{
|
|||||||
|
|
||||||
// Smooth movement
|
// Smooth movement
|
||||||
if (targetNoY.magnitude > currentNoY.magnitude) {
|
if (targetNoY.magnitude > currentNoY.magnitude) {
|
||||||
currentNoY = Vector3.Lerp(currentNoY, targetNoY,data.accelerationSmoothing * Time.deltaTime);
|
currentNoY = Vector3.Slerp(currentNoY, targetNoY,data.accelerationSmoothing * Time.deltaTime);
|
||||||
|
|
||||||
} else {
|
} else {
|
||||||
float deaccelValue = data.deaccelerationCurve.Evaluate(inputMovement.magnitude);
|
float deaccelValue = data.deaccelerationCurve.Evaluate(inputMovement.magnitude);
|
||||||
@@ -164,28 +143,28 @@ namespace Reset.Units{
|
|||||||
Vector3 inputMovement = new Vector3(controls.rawMoveInput.x, 0f, controls.rawMoveInput.y);
|
Vector3 inputMovement = new Vector3(controls.rawMoveInput.x, 0f, controls.rawMoveInput.y);
|
||||||
|
|
||||||
switch (data.rotateFacing) {
|
switch (data.rotateFacing) {
|
||||||
|
// TODO: Recomment
|
||||||
case PlayerFacingDirection.TowardsTarget:
|
case PlayerFacingDirection.TowardsTarget:
|
||||||
// Set rotation to just the direction of the target
|
|
||||||
|
|
||||||
Debug.LogError("Not implemented...");
|
Debug.LogError("Not implemented...");
|
||||||
|
break;
|
||||||
|
case PlayerFacingDirection.Momentum:
|
||||||
|
if (inputMovement.magnitude > .03f){
|
||||||
|
outputRotation = Camera.main.transform.rotation * Quaternion.LookRotation(outputMoveDirection);
|
||||||
|
}
|
||||||
break;
|
break;
|
||||||
case PlayerFacingDirection.MatchForward:
|
case PlayerFacingDirection.MatchForward:
|
||||||
if (controls.rawMoveInput.magnitude < 0.01f) { break; }
|
if (controls.rawMoveInput.magnitude < 0.01f) { break; }
|
||||||
|
outputRotation = Camera.main.transform.rotation * Quaternion.LookRotation(inputMovement);
|
||||||
outputRotation = Quaternion.LookRotation(inputMovement) *
|
|
||||||
Quaternion.Euler(Camera.main.transform.rotation.eulerAngles.Flatten(0f, null, 0f));
|
|
||||||
|
|
||||||
break;
|
break;
|
||||||
case PlayerFacingDirection.MatchCamera:
|
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));
|
||||||
outputRotation = Quaternion.Euler(Camera.main.transform.rotation.eulerAngles.Flatten(0, null, 0));
|
|
||||||
break;
|
break;
|
||||||
case PlayerFacingDirection.Static:
|
case PlayerFacingDirection.Static:
|
||||||
outputRotation = transform.rotation;
|
outputRotation = transform.rotation;
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
|
||||||
// Set final rotation
|
// Set final rotation
|
||||||
transform.rotation = Quaternion.Lerp(transform.rotation, outputRotation, 10f * Time.deltaTime).Flatten(0, null, 0);
|
transform.rotation = Quaternion.Lerp(transform.rotation, outputRotation, 10f * Time.deltaTime).Flatten(0, null, 0);
|
||||||
@@ -196,7 +175,7 @@ namespace Reset.Units{
|
|||||||
}
|
}
|
||||||
|
|
||||||
public void DoMovement(Vector3 moveDir, float speed){
|
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));
|
controller.Move((Camera.main.transform.rotation.Flatten(0, null, 0) * (moveDir * speed) * Time.deltaTime));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user