changed: tweaks to make grapple feel better
This commit is contained in:
@@ -2,6 +2,7 @@ using Drawing;
|
||||
using NodeCanvas.Framework;
|
||||
using ParadoxNotion.Design;
|
||||
using ParadoxNotion.Services;
|
||||
using Reset.Units;
|
||||
using UnityEngine;
|
||||
|
||||
|
||||
@@ -9,7 +10,7 @@ namespace NodeCanvas.Tasks.Actions {
|
||||
|
||||
[Category("Reset/Movement")]
|
||||
[Description("Pulls the agent towards a position with a spring-like effect")]
|
||||
public class DoGrapplePull : ActionTask<CharacterController>{
|
||||
public class DoGrapplePull : ActionTask<UnitMovementHandler>{
|
||||
public BBParameter<Vector3> grapplePoint;
|
||||
public BBParameter<Vector3> offset;
|
||||
|
||||
@@ -26,17 +27,25 @@ namespace NodeCanvas.Tasks.Actions {
|
||||
public BBParameter<AnimationCurve> pullSpeedCurve;
|
||||
public BBParameter<AnimationCurve> endDeaccelerationCurve;
|
||||
|
||||
|
||||
private float startTime;
|
||||
|
||||
private Vector3 originalDirection;
|
||||
|
||||
public float breakAtDistance;
|
||||
public float breakAtDotProduct;
|
||||
|
||||
private float currentSpeed;
|
||||
private Vector3 smoothedInput;
|
||||
private Vector3 smoothedInputRefVelocity;
|
||||
|
||||
private Vector3 gizmoHookPoint;
|
||||
|
||||
private Transform camera;
|
||||
|
||||
//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
|
||||
protected override string OnInit(){
|
||||
MonoManager.current.onLateUpdate += DrawGrappleGizmo;
|
||||
|
||||
return null;
|
||||
}
|
||||
|
||||
@@ -44,14 +53,25 @@ namespace NodeCanvas.Tasks.Actions {
|
||||
//Call EndAction() to mark the action as finished, either in success or failure.
|
||||
//EndAction can be called from anywhere.
|
||||
protected override void OnExecute(){
|
||||
camera = Camera.main.transform;
|
||||
MonoManager.current.onLateUpdate += DrawGrappleGizmo;
|
||||
originalDirection = agent.transform.position.DirectionTo(grapplePoint.value);
|
||||
startTime = Time.time;
|
||||
currentSpeed = pullSpeedCurve.value[0].value * pullSpeedRange.value.y;
|
||||
}
|
||||
|
||||
//Called once per frame while the action is active.
|
||||
protected override void OnUpdate(){
|
||||
protected override void OnUpdate(){
|
||||
// Add input changes
|
||||
Vector2 rawInput = agent.GetComponent<PlayerControls>().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);
|
||||
|
||||
smoothedInput = Vector3.SmoothDamp(smoothedInput, input, ref smoothedInputRefVelocity, 5f * Time.deltaTime);
|
||||
|
||||
// Create the distance variables
|
||||
Vector3 dirToPoint = agent.transform.position.DirectionTo(grapplePoint.value);
|
||||
Vector3 dirToPoint = agent.transform.position.DirectionTo(grapplePoint.value + (smoothedInput * 5));
|
||||
gizmoHookPoint = grapplePoint.value + (smoothedInput * 5);
|
||||
|
||||
float evaluatedSpeed = pullSpeedCurve.value.Evaluate(Mathf.Clamp((Time.time - startTime) / 6f, 0f, Mathf.Infinity));
|
||||
|
||||
@@ -78,40 +98,30 @@ namespace NodeCanvas.Tasks.Actions {
|
||||
// Soften the speed changes
|
||||
currentSpeed = Mathf.Lerp(currentSpeed, speedAgainstCurve, 10f * Time.deltaTime);
|
||||
|
||||
// Add input changes
|
||||
Vector2 rawInput = agent.GetComponent<PlayerControls>().rawMoveInput;
|
||||
Vector3 input = Quaternion.LookRotation(dirToPoint) * new Vector3(rawInput.x, rawInput.y, 0f);
|
||||
|
||||
smoothedInput = Vector3.SmoothDamp(smoothedInput, input, ref smoothedInputRefVelocity, 30f * Time.deltaTime);
|
||||
|
||||
Debug.Log(input);
|
||||
|
||||
Debug.Log(dirToPoint);
|
||||
dirToPoint.y *= 2.5f;
|
||||
|
||||
agent.Move((dirToPoint.normalized + smoothedInput) * currentSpeed * Time.deltaTime);
|
||||
// agent.GetComponent<CharacterController>().Move((dirToPoint.normalized + smoothedInput) * currentSpeed * Time.deltaTime);
|
||||
agent.AddToCurrentDirection((dirToPoint + smoothedInput), currentSpeed * Time.deltaTime);
|
||||
// agent.DisableNextMoveCall();
|
||||
|
||||
// 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(){
|
||||
// Vector3 dirToPoint = agent.transform.position.DirectionTo(grapplePoint.value);
|
||||
//
|
||||
// using (Draw.WithColor(Color.yellow)){
|
||||
// Draw.Line(agent.transform.position + Vector3.up, grapplePoint.value);
|
||||
//
|
||||
// // Draw Gizmo for minimum distance
|
||||
// Vector3 minLocation = agent.transform.position + (Vector3.up * 1) + (dirToPoint * pullSpeedDistances.value.x);
|
||||
// Vector3 minToScreen = minLocation.DirectionTo(Camera.main.transform.position);
|
||||
//
|
||||
// Draw.SolidCircle(minLocation,minToScreen , .2f);
|
||||
//
|
||||
// // Draw Gizmo for minimum distance
|
||||
// Vector3 maxLocation = agent.transform.position + (Vector3.up * .8f) + (dirToPoint * pullSpeedDistances.value.y);
|
||||
// Vector3 maxToScreen = maxLocation.DirectionTo(Camera.main.transform.position);
|
||||
//
|
||||
// Draw.SolidCircle(maxLocation,maxToScreen , .2f);
|
||||
// }
|
||||
using (Draw.WithColor(Color.blue)){
|
||||
Draw.SolidCircle(gizmoHookPoint, gizmoHookPoint.DirectionTo(camera.position), 1f);
|
||||
}
|
||||
}
|
||||
|
||||
//Called when the task is disabled.
|
||||
|
||||
Reference in New Issue
Block a user