changed: redoing grapple again, freshly started
This commit is contained in:
@@ -1,10 +1,14 @@
|
||||
using System;
|
||||
using System.Numerics;
|
||||
using NUnit.Framework.Internal;
|
||||
using UnityEngine;
|
||||
using ParadoxNotion.Design;
|
||||
using Sirenix.OdinInspector;
|
||||
using UnityEditor.Rendering;
|
||||
using UnityEngine.Serialization;
|
||||
using Quaternion = UnityEngine.Quaternion;
|
||||
using Vector2 = UnityEngine.Vector2;
|
||||
using Vector3 = UnityEngine.Vector3;
|
||||
|
||||
public enum PlayerFacingDirection{
|
||||
TowardsTarget = 0,
|
||||
@@ -81,6 +85,8 @@ namespace Reset.Units{
|
||||
|
||||
private float directionChangeDot;
|
||||
private bool moveCallDisabledNextFrame;
|
||||
|
||||
private bool movedThisFrame;
|
||||
|
||||
private CharacterController controller;
|
||||
private PlayerControls controls;
|
||||
@@ -89,6 +95,8 @@ namespace Reset.Units{
|
||||
private Vector3 moveSmooth;
|
||||
public float gravitySmooth;
|
||||
|
||||
private bool relativeToCamera;
|
||||
|
||||
[ShowInInspector, PropertyOrder(2)]
|
||||
public UnitMovementData data = new();
|
||||
|
||||
@@ -113,8 +121,6 @@ namespace Reset.Units{
|
||||
UpdateCurrentRotation();
|
||||
|
||||
DoMovement();
|
||||
|
||||
|
||||
}
|
||||
|
||||
// Add directly to the direction
|
||||
@@ -123,9 +129,31 @@ namespace Reset.Units{
|
||||
additionalSpeed = power;
|
||||
}
|
||||
|
||||
public void SetNewDirection(Vector3 inputDirection, float power){
|
||||
additionalMoveDirection = inputDirection.normalized;
|
||||
additionalSpeed = power * Time.deltaTime;
|
||||
public void SmoothToDirection(Vector3 desiredDirection, float value, out Vector3 referenceDirection){
|
||||
// referenceDirection = outputMoveDirection;
|
||||
|
||||
additionalMoveDirection = Vector3.Slerp(outputMoveDirection, desiredDirection, value);
|
||||
|
||||
referenceDirection = outputMoveDirection;
|
||||
}
|
||||
|
||||
public void SmoothToSpeed(float desiredSpeed, float smoothing, out float referenceSpeed){
|
||||
additionalSpeed = Mathf.Lerp(outputSpeed, desiredSpeed, smoothing * Time.deltaTime);
|
||||
|
||||
referenceSpeed = additionalSpeed;
|
||||
}
|
||||
|
||||
// public void SmoothToGravity(float desiredGravity, float smoothing, out float referenceGravity){
|
||||
// outputMoveDirection.y = Mathf.Lerp(outputMoveDirection.y, desiredGravity, smoothing);
|
||||
// referenceGravity = desiredGravity;
|
||||
// }
|
||||
|
||||
public void SetNewDirection(Vector3 inputDirection){ // NOTE: If smoothing desired add a default bool for smoothing maybe?
|
||||
additionalMoveDirection = inputDirection.Flatten(null, 0f, null);
|
||||
}
|
||||
|
||||
public void SetNewGravity(float value){
|
||||
additionalMoveDirection.y = value;
|
||||
}
|
||||
|
||||
// Hold a new rotation to be moved to during PlayerFacingDirection.SpecifiedRotation
|
||||
@@ -151,7 +179,7 @@ namespace Reset.Units{
|
||||
if (float.IsPositiveInfinity(speed)) {
|
||||
return;
|
||||
}
|
||||
|
||||
|
||||
outputSpeed = Mathf.Lerp(outputSpeed, Mathf.Max(data.moveSpeed, speed), priority);
|
||||
}
|
||||
|
||||
@@ -210,6 +238,7 @@ namespace Reset.Units{
|
||||
|
||||
// Update the speed, called every frame
|
||||
private void UpdateCurrentSpeed(){
|
||||
Debug.Log(data.moveSpeed);
|
||||
outputSpeed = Mathf.Lerp(outputSpeed, data.moveSpeed, data.moveSpeedSoothing * Time.deltaTime);
|
||||
}
|
||||
|
||||
@@ -228,7 +257,7 @@ namespace Reset.Units{
|
||||
float gravityMoveDirection = data.jumpPower + (Physics.gravity.y * data.gravityPower);
|
||||
|
||||
// Commit gravity to move direction, ignoring XZ since those are done in UpdateMovementDirection
|
||||
outputMoveDirection.y = Mathf.SmoothDamp(outputMoveDirection.y, gravityMoveDirection, ref gravitySmooth, .1f * Time.deltaTime);
|
||||
// outputMoveDirection.y = Mathf.SmoothDamp(outputMoveDirection.y, gravityMoveDirection, ref gravitySmooth, .1f * Time.deltaTime);
|
||||
}
|
||||
|
||||
// Update the rotation, called every frame
|
||||
@@ -291,17 +320,8 @@ namespace Reset.Units{
|
||||
}
|
||||
|
||||
// Custom move from input
|
||||
public void DoMovement(Vector3 moveDir, float speed, float gravityScale, bool relativeToCamera = true){
|
||||
if (moveCallDisabledNextFrame) {
|
||||
// Vector3 velocity = transform.InverseTransformDirection(controller.velocity.normalized);
|
||||
// outputMoveDirection = new Vector3(velocity.x, outputMoveDirection.y, velocity.z);
|
||||
|
||||
|
||||
moveCallDisabledNextFrame = false;
|
||||
return;
|
||||
}
|
||||
|
||||
Debug.Log($"moveDir: {moveDir}, agent velocity: {transform.InverseTransformDirection(controller.velocity.normalized)}");
|
||||
public void DoMovement(Vector3 moveDir, float speed, float gravityScale){
|
||||
// Debug.Log($"moveDir: {moveDir}, agent velocity: {transform.InverseTransformDirection(controller.velocity.normalized)}");
|
||||
|
||||
// Seperate the different move directions. Additonal becomes it's own because it needs to be added independently of the other two
|
||||
Vector3 moveXZDir = new Vector3(moveDir.x, 0f, moveDir.z);
|
||||
@@ -316,11 +336,9 @@ namespace Reset.Units{
|
||||
// Construct the direction and move
|
||||
Vector3 finalDir = moveXZDir + moveYDir;
|
||||
|
||||
if (relativeToCamera) {
|
||||
|
||||
controller.Move((Camera.main.transform.rotation.Flatten(0, null, 0) * finalDir) + addDir);
|
||||
} else {
|
||||
controller.Move(finalDir + addDir);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
void LateUpdate(){
|
||||
|
||||
Reference in New Issue
Block a user