From 3e0a6885fb168a7d97a8bf74da9f71ed6d65f1fe Mon Sep 17 00:00:00 2001 From: Chris Date: Thu, 21 Aug 2025 22:12:28 -0400 Subject: [PATCH] changed: more grapple tweaks and fixes --- .../Graph Tasks/ChangeMovementSettings.cs | 2 +- .../Scripts/Core/Graph Tasks/DoGrapplePull.cs | 52 ++++++++++++++----- Assets/Scripts/Player/UnitMovementHandler.cs | 12 ++++- 3 files changed, 51 insertions(+), 15 deletions(-) diff --git a/Assets/Scripts/Core/Graph Tasks/ChangeMovementSettings.cs b/Assets/Scripts/Core/Graph Tasks/ChangeMovementSettings.cs index 80193da..f1b895c 100644 --- a/Assets/Scripts/Core/Graph Tasks/ChangeMovementSettings.cs +++ b/Assets/Scripts/Core/Graph Tasks/ChangeMovementSettings.cs @@ -98,7 +98,7 @@ namespace Reset.Core { UpdateFloatValue(gravityMax, ref agent.data.gravityMax, ref agent.defaultData.gravityMax); UpdateFloatValue(gravityAcceleration, ref agent.data.gravityAcceleration, ref agent.defaultData.gravityAcceleration); UpdateFloatValue(gravityScale, ref agent.data.gravityScale, ref agent.defaultData.gravityScale); - UpdateFloatValue(settingsChangeSmoothing, ref agent.data.settingsChangeSmoothing, ref agent.data.settingsChangeSmoothing); + UpdateFloatValue(settingsChangeSmoothing, ref agent.data.settingsChangeSmoothing, ref agent.defaultData.settingsChangeSmoothing); // Rotation UpdateEnumValue(rotateFacing, ref agent.data.rotateFacing, ref agent.defaultData.rotateFacing); diff --git a/Assets/Scripts/Core/Graph Tasks/DoGrapplePull.cs b/Assets/Scripts/Core/Graph Tasks/DoGrapplePull.cs index 3ca24d8..848ee97 100644 --- a/Assets/Scripts/Core/Graph Tasks/DoGrapplePull.cs +++ b/Assets/Scripts/Core/Graph Tasks/DoGrapplePull.cs @@ -30,7 +30,9 @@ namespace NodeCanvas.Tasks.Actions { private float startTime; private Vector3 originalDirection; - + public float originalDistance; + public Vector3 originalLocation; + public float breakAtDistance; public float breakAtDotProduct; @@ -39,8 +41,14 @@ namespace NodeCanvas.Tasks.Actions { private Vector3 smoothedInputRefVelocity; private Vector3 gizmoHookPoint; + private Vector3 gizmoCenterPoint; + private Vector3 gizmoDirection; + private Vector3 gizmoStartPos; + private Vector3 gizmoEndPos; private Transform camera; + + private Vector3 finalDirection; //Use for initialization. This is called only once in the lifetime of the task. //Return null if init was successfull. Return an error string otherwise @@ -55,9 +63,12 @@ namespace NodeCanvas.Tasks.Actions { protected override void OnExecute(){ camera = Camera.main.transform; MonoManager.current.onLateUpdate += DrawGrappleGizmo; + originalLocation = agent.transform.position; originalDirection = agent.transform.position.DirectionTo(grapplePoint.value); + originalDistance = Vector3.Distance(agent.transform.position, grapplePoint.value); startTime = Time.time; currentSpeed = pullSpeedCurve.value[0].value * pullSpeedRange.value.y; + finalDirection = Vector3.zero; } //Called once per frame while the action is active. @@ -65,12 +76,20 @@ namespace NodeCanvas.Tasks.Actions { // Add input changes Vector2 rawInput = agent.GetComponent().rawMoveInput; Vector3 input = Quaternion.LookRotation(agent.transform.position.DirectionTo(grapplePoint.value)) * new Vector3(rawInput.x, rawInput.y, 0f); - input = Quaternion.LookRotation(agent.transform.position.DirectionTo(grapplePoint.value)) * (camera.rotation * input); + // input = Quaternion.LookRotation(agent.transform.position.DirectionTo(grapplePoint.value)) * (camera.rotation * input); smoothedInput = Vector3.SmoothDamp(smoothedInput, input, ref smoothedInputRefVelocity, 5f * Time.deltaTime); // Create the distance variables - Vector3 dirToPoint = agent.transform.position.DirectionTo(grapplePoint.value + (smoothedInput * 5)); + Vector3 dirToPoint = agent.transform.position.DirectionTo(grapplePoint.value + (smoothedInput * 6)); + float currentDist = Vector3.Distance(agent.transform.position, grapplePoint.value); + + var center = agent.transform.position + agent.transform.position.DirectionTo(grapplePoint.value).normalized * 5f; + + // finalDirection = Vector3.Slerp(finalDirection, dirToPoint, originalDistance); + // finalDirection = Vector3.Slerp(relativeStart, relativeEnd, currentDist / 5f); + finalDirection = Vector3.Slerp(finalDirection, dirToPoint + smoothedInput, currentDist / 5f); + gizmoHookPoint = grapplePoint.value + (smoothedInput * 5); float evaluatedSpeed = pullSpeedCurve.value.Evaluate(Mathf.Clamp((Time.time - startTime) / 6f, 0f, Mathf.Infinity)); @@ -79,7 +98,6 @@ namespace NodeCanvas.Tasks.Actions { // Find how far from 0-1 the player is from the max and minimum distance // Get the base distance then account for the minimum distance to the point so that being the minimum away will Lerp to 1 - float currentDist = Vector3.Distance(agent.transform.position, grapplePoint.value); // float currentDistMinimumAccounted = (currentDist - pullSpeedDistances.value.x); if (currentDist < slowdownDistance.value) { @@ -101,32 +119,42 @@ namespace NodeCanvas.Tasks.Actions { Debug.Log(dirToPoint); dirToPoint.y *= 2.5f; + gizmoDirection = finalDirection; // agent.GetComponent().Move((dirToPoint.normalized + smoothedInput) * currentSpeed * Time.deltaTime); - agent.AddToCurrentDirection((dirToPoint + smoothedInput), currentSpeed * Time.deltaTime); - // agent.DisableNextMoveCall(); + agent.AddToCurrentDirection(finalDirection, currentSpeed * Time.deltaTime); // Debug.Log( $"{ endDeaccelerationCurve.value.Evaluate(((slowdownDistance.value - currentDist)) )}"); if (Vector3.Dot(originalDirection, dirToPoint) < breakAtDotProduct) { - MonoManager.current.onLateUpdate -= DrawGrappleGizmo; EndAction(true); } else if (currentDist < breakAtDistance) { - MonoManager.current.onLateUpdate -= DrawGrappleGizmo; EndAction(true); } - - // EndAction(true); } public void DrawGrappleGizmo(){ using (Draw.WithColor(Color.blue)){ - Draw.SolidCircle(gizmoHookPoint, gizmoHookPoint.DirectionTo(camera.position), 1f); + Draw.Arrow(agent.transform.position, agent.transform.position + gizmoDirection); + Draw.SolidCircle(grapplePoint.value, grapplePoint.value.DirectionTo(camera.position), 1f); + + } + + using (Draw.WithColor(Color.yellow)) { + Draw.Arrow(grapplePoint.value, gizmoHookPoint); + } + + using (Draw.WithColor(Color.red)) { + Draw.SolidCircle(gizmoCenterPoint, gizmoCenterPoint.DirectionTo(camera.position), .2f); + } + + using (Draw.WithColor(Color.magenta)) { + Draw.Line(agent.transform.position, grapplePoint.value); } } //Called when the task is disabled. protected override void OnStop() { - + MonoManager.current.onLateUpdate -= DrawGrappleGizmo; } //Called when the task is paused. diff --git a/Assets/Scripts/Player/UnitMovementHandler.cs b/Assets/Scripts/Player/UnitMovementHandler.cs index d876e7f..848cc76 100644 --- a/Assets/Scripts/Player/UnitMovementHandler.cs +++ b/Assets/Scripts/Player/UnitMovementHandler.cs @@ -123,6 +123,11 @@ namespace Reset.Units{ additionalSpeed = power; } + public void SetNewDirection(Vector3 inputDirection, float power){ + additionalMoveDirection = inputDirection.normalized; + additionalSpeed = power * Time.deltaTime; + } + // Hold a new rotation to be moved to during PlayerFacingDirection.SpecifiedRotation public void SetSpecifiedRotation(Quaternion inputRotation){ specifiedRotation = inputRotation; @@ -288,8 +293,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); + // Vector3 velocity = transform.InverseTransformDirection(controller.velocity.normalized); + // outputMoveDirection = new Vector3(velocity.x, outputMoveDirection.y, velocity.z); moveCallDisabledNextFrame = false; @@ -347,6 +352,8 @@ namespace Reset.Units{ 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); @@ -354,6 +361,7 @@ namespace Reset.Units{ // Decay the gravity additionalMoveDirection.y -= data.gravityPower; + additionalMoveDirection.y = Mathf.Max(0f, additionalMoveDirection.y); } private void UpdateGravityLate(){