refactor: PlayerFacingDirection.cs renamed to UnitFacingDirection.cs
This commit is contained in:
@@ -8,7 +8,7 @@ namespace Reset.Units {
|
|||||||
|
|
||||||
[Category("Reset/Movement")]
|
[Category("Reset/Movement")]
|
||||||
public class ChangeRotationSettings : ActionTask<UnitMovementHandler> {
|
public class ChangeRotationSettings : ActionTask<UnitMovementHandler> {
|
||||||
[SerializeField] public EnumValueGroup facingDirection = new EnumValueGroup("Facing Direction", PlayerFacingDirection.TowardsTarget);
|
[SerializeField] public EnumValueGroup facingDirection = new EnumValueGroup("Facing Direction", UnitFacingDirection.TowardsTarget);
|
||||||
[SerializeField] public FloatValueGroup rotationSpeed = new (newLabel: "Rotation Speed");
|
[SerializeField] public FloatValueGroup rotationSpeed = new (newLabel: "Rotation Speed");
|
||||||
|
|
||||||
//Use for initialization. This is called only once in the lifetime of the task.
|
//Use for initialization. This is called only once in the lifetime of the task.
|
||||||
|
|||||||
@@ -1,5 +1,5 @@
|
|||||||
namespace Reset.Units{
|
namespace Reset.Units{
|
||||||
public enum PlayerFacingDirection{
|
public enum UnitFacingDirection{
|
||||||
TowardsTarget = 0,
|
TowardsTarget = 0,
|
||||||
MatchInput,
|
MatchInput,
|
||||||
MatchCamera,
|
MatchCamera,
|
||||||
@@ -31,7 +31,7 @@ namespace Reset.Units{
|
|||||||
[Title("Gravity Scale"), HideLabel, InlineProperty] public SettingValue<float> gravityScale = new SettingValue<float>(1f);
|
[Title("Gravity Scale"), HideLabel, InlineProperty] public SettingValue<float> gravityScale = new SettingValue<float>(1f);
|
||||||
|
|
||||||
// Rotation
|
// Rotation
|
||||||
[Title("Rotate Facing"), HideLabel, InlineProperty] public SettingValue<PlayerFacingDirection> facingDirection = new SettingValue<PlayerFacingDirection>(initValue: PlayerFacingDirection.Momentum);
|
[Title("Rotate Facing"), HideLabel, InlineProperty] public SettingValue<UnitFacingDirection> facingDirection = new SettingValue<UnitFacingDirection>(initValue: UnitFacingDirection.Momentum);
|
||||||
[Title("Rotation Speed"), HideLabel, InlineProperty] public SettingValue<float> rotationSpeed = new SettingValue<float>(5f);
|
[Title("Rotation Speed"), HideLabel, InlineProperty] public SettingValue<float> rotationSpeed = new SettingValue<float>(5f);
|
||||||
|
|
||||||
|
|
||||||
|
|||||||
@@ -141,12 +141,12 @@ namespace Reset.Units{
|
|||||||
// Switch the desired rotation based on current movement setting
|
// Switch the desired rotation based on current movement setting
|
||||||
switch (data.facingDirection.Value) {
|
switch (data.facingDirection.Value) {
|
||||||
// Just look at target
|
// Just look at target
|
||||||
case PlayerFacingDirection.TowardsTarget:
|
case UnitFacingDirection.TowardsTarget:
|
||||||
// Look directly at the target
|
// Look directly at the target
|
||||||
if (targetProvider.UnitTarget == null) {
|
if (targetProvider.UnitTarget == null) {
|
||||||
Debug.LogError("Trying to rotate towards a target but there is no target. Forcing rotation to Static and continuing");
|
Debug.LogError("Trying to rotate towards a target but there is no target. Forcing rotation to Static and continuing");
|
||||||
data.facingDirection.Value = PlayerFacingDirection.Static;
|
data.facingDirection.Value = UnitFacingDirection.Static;
|
||||||
data.facingDirection.currentValue = PlayerFacingDirection.Static;
|
data.facingDirection.currentValue = UnitFacingDirection.Static;
|
||||||
|
|
||||||
targetRotation = transform.rotation;
|
targetRotation = transform.rotation;
|
||||||
break;
|
break;
|
||||||
@@ -154,23 +154,23 @@ namespace Reset.Units{
|
|||||||
|
|
||||||
targetRotation = Quaternion.LookRotation(transform.position.DirectionTo(targetProvider.UnitTarget.transform.position));
|
targetRotation = Quaternion.LookRotation(transform.position.DirectionTo(targetProvider.UnitTarget.transform.position));
|
||||||
break;
|
break;
|
||||||
case PlayerFacingDirection.Momentum:
|
case UnitFacingDirection.Momentum:
|
||||||
// Look towards the current direction the agent is moving
|
// Look towards the current direction the agent is moving
|
||||||
if (inputMovement.magnitude > .05f){
|
if (inputMovement.magnitude > .05f){
|
||||||
targetRotation = Quaternion.LookRotation(resolvedMovement.moveDirection.RawWorld.ToVector3(), Vector3.up);
|
targetRotation = Quaternion.LookRotation(resolvedMovement.moveDirection.RawWorld.ToVector3(), Vector3.up);
|
||||||
}
|
}
|
||||||
break;
|
break;
|
||||||
case PlayerFacingDirection.MatchInput:
|
case UnitFacingDirection.MatchInput:
|
||||||
// Look towards the input direction- similar to Momentum but snappier
|
// Look towards the input direction- similar to Momentum but snappier
|
||||||
if (directionProvider.Direction.magnitude < 0.05f) { break; }
|
if (directionProvider.Direction.magnitude < 0.05f) { break; }
|
||||||
|
|
||||||
targetRotation = Camera.main.transform.rotation * Quaternion.LookRotation(inputMovement);
|
targetRotation = Camera.main.transform.rotation * Quaternion.LookRotation(inputMovement);
|
||||||
break;
|
break;
|
||||||
case PlayerFacingDirection.MatchCamera:
|
case UnitFacingDirection.MatchCamera:
|
||||||
// Look the same direction as the camera
|
// Look the same direction as the camera
|
||||||
targetRotation = Quaternion.Euler(Camera.main.transform.rotation.eulerAngles.Flatten(0, null, 0));
|
targetRotation = Quaternion.Euler(Camera.main.transform.rotation.eulerAngles.Flatten(0, null, 0));
|
||||||
break;
|
break;
|
||||||
case PlayerFacingDirection.Static:
|
case UnitFacingDirection.Static:
|
||||||
// Don't change
|
// Don't change
|
||||||
targetRotation = resolvedMovement.rotation;
|
targetRotation = resolvedMovement.rotation;
|
||||||
break;
|
break;
|
||||||
@@ -179,7 +179,7 @@ namespace Reset.Units{
|
|||||||
DebugOverlayDrawer.ChangeValue("Rotation", "Target Rotation", targetRotation.eulerAngles);
|
DebugOverlayDrawer.ChangeValue("Rotation", "Target Rotation", targetRotation.eulerAngles);
|
||||||
|
|
||||||
// Add the current input into the created rotation
|
// Add the current input into the created rotation
|
||||||
if (data.facingDirection.Value == PlayerFacingDirection.MatchCamera || data.facingDirection.Value == PlayerFacingDirection.TowardsTarget) {
|
if (data.facingDirection.Value == UnitFacingDirection.MatchCamera || data.facingDirection.Value == UnitFacingDirection.TowardsTarget) {
|
||||||
resolvedMovement.rotation = targetRotation;
|
resolvedMovement.rotation = targetRotation;
|
||||||
} else if (directionProvider.Direction.sqrMagnitude > .1){
|
} else if (directionProvider.Direction.sqrMagnitude > .1){
|
||||||
resolvedMovement.rotation = targetRotation;
|
resolvedMovement.rotation = targetRotation;
|
||||||
|
|||||||
Reference in New Issue
Block a user