added: movement settings changing within graph
This commit is contained in:
@@ -10,7 +10,8 @@ public enum PlayerFacingDirection{
|
||||
MatchForward,
|
||||
MatchCamera,
|
||||
Static,
|
||||
Momentum
|
||||
Momentum,
|
||||
SpecifiedDirection
|
||||
}
|
||||
|
||||
namespace Reset.Units{
|
||||
@@ -41,13 +42,10 @@ namespace Reset.Units{
|
||||
public float gravityScale = 1f;
|
||||
|
||||
// Rotation
|
||||
public PlayerFacingDirection rotateFacing;
|
||||
[ShowInInspector, SerializeReference]
|
||||
public Enum rotateFacing;
|
||||
public float rotationSpeedTarget = 5f;
|
||||
public float rotationSmoothing = 1f;
|
||||
|
||||
// Smoothing
|
||||
public Quaternion targetRotation;
|
||||
public float currentRotSpeed;
|
||||
|
||||
public object Clone(){
|
||||
return this.MemberwiseClone();
|
||||
@@ -63,16 +61,23 @@ namespace Reset.Units{
|
||||
// Debug viewing
|
||||
// Smoothed Values
|
||||
[ShowInInspector, ReadOnly] private float outputSpeed;
|
||||
[ShowInInspector, ReadOnly] private float additionalSpeed;
|
||||
[ShowInInspector, ReadOnly] private Vector3 outputMoveDirection;
|
||||
[ShowInInspector, ReadOnly] private Vector3 additionalMoveDirection;
|
||||
[ShowInInspector, ReadOnly] private Quaternion outputRotation;
|
||||
[ShowInInspector, ReadOnly] private Quaternion specifiedRotation;
|
||||
[ShowInInspector, ReadOnly] private float outputRotationSpeed;
|
||||
|
||||
|
||||
private CharacterController controller;
|
||||
public PlayerControls controls;
|
||||
|
||||
[ShowInInspector, PropertyOrder(2)]
|
||||
public UnitMovementData data = new UnitMovementData();
|
||||
|
||||
[HideInInspector]
|
||||
public UnitMovementData defaultData;
|
||||
|
||||
[Button, PropertyOrder(1)]
|
||||
void ResetMovementData(){
|
||||
data = new UnitMovementData();
|
||||
@@ -82,6 +87,10 @@ namespace Reset.Units{
|
||||
controller = GetComponent<CharacterController>();
|
||||
}
|
||||
|
||||
private void Start(){
|
||||
defaultData = (UnitMovementData)data.Clone();
|
||||
}
|
||||
|
||||
void Update(){
|
||||
UpdateCurrentDirection();
|
||||
UpdateCurrentSpeed();
|
||||
@@ -90,6 +99,15 @@ namespace Reset.Units{
|
||||
|
||||
DoMovement();
|
||||
}
|
||||
|
||||
public void AddToCurrentDirection(Vector3 inputDirection, float power){
|
||||
additionalMoveDirection += inputDirection.normalized;
|
||||
additionalSpeed = power;
|
||||
}
|
||||
|
||||
public void SetSpecifiedRotation(Quaternion inputRotation){
|
||||
specifiedRotation = inputRotation;
|
||||
}
|
||||
|
||||
private void UpdateCurrentDirection(){
|
||||
// Get input value
|
||||
@@ -167,6 +185,9 @@ namespace Reset.Units{
|
||||
case PlayerFacingDirection.Static:
|
||||
outputRotation = transform.rotation;
|
||||
break;
|
||||
case PlayerFacingDirection.SpecifiedDirection:
|
||||
outputRotation = specifiedRotation;
|
||||
break;
|
||||
}
|
||||
|
||||
// Calculate rotation speed
|
||||
@@ -184,22 +205,48 @@ namespace Reset.Units{
|
||||
// Commit the move, with respect to the camera's rotation
|
||||
Vector3 moveXZDir = new Vector3(moveDir.x, 0f, moveDir.z);
|
||||
Vector3 moveYDir = new Vector3(0f, moveDir.y, 0f);
|
||||
Vector3 addDir = additionalMoveDirection;
|
||||
|
||||
moveXZDir *= speed * Time.deltaTime;
|
||||
moveYDir *= gravity * Time.deltaTime;
|
||||
addDir *= additionalSpeed * Time.deltaTime;
|
||||
|
||||
Vector3 finalDir = moveXZDir + moveYDir;
|
||||
|
||||
controller.Move((Camera.main.transform.rotation.Flatten(0, null, 0) * finalDir));
|
||||
controller.Move((Camera.main.transform.rotation.Flatten(0, null, 0) * finalDir) + addDir);
|
||||
}
|
||||
|
||||
public void LateUpdate(){
|
||||
void LateUpdate(){
|
||||
UpdateGravityLate();
|
||||
DecayAdditionalDirection();
|
||||
}
|
||||
|
||||
void DecayAdditionalDirection(){
|
||||
// Get input value
|
||||
Vector3 inputMovement = new Vector3(controls.rawMoveInput.x, 0f, controls.rawMoveInput.y);
|
||||
|
||||
// Ignore values under deadzone
|
||||
if (inputMovement.magnitude < .1f) {
|
||||
inputMovement = Vector3.zero;
|
||||
}
|
||||
|
||||
// Remove Y from variables
|
||||
Vector3 currentNoY = new Vector3(additionalMoveDirection.x, 0f, additionalMoveDirection.z);
|
||||
|
||||
if (inputMovement.magnitude < currentNoY.magnitude) {
|
||||
additionalMoveDirection = Vector3.Slerp(additionalMoveDirection, Vector3.zero,data.accelerationSmoothing * Time.deltaTime);
|
||||
|
||||
} else {
|
||||
// float deaccelValue = data.deaccelerationCurve.Evaluate(inputMovement.magnitude);
|
||||
|
||||
additionalMoveDirection = Vector3.Lerp(additionalMoveDirection, Vector3.zero, data.deaccelerationSmoothing * Time.deltaTime);
|
||||
}
|
||||
}
|
||||
|
||||
private void UpdateGravityLate(){
|
||||
// Decay jump power
|
||||
data.jumpPower -= data.jumpPowerDecay * Time.deltaTime;
|
||||
data.jumpPower = Mathf.Max(0f, data.jumpPower);
|
||||
}
|
||||
|
||||
public void AssignNewData(UnitMovementData movementData){
|
||||
|
||||
Reference in New Issue
Block a user