added: rudimentary grapple line renderer

This commit is contained in:
Chris
2025-08-31 12:37:57 -04:00
parent f87c5a2cb7
commit 9e963784e3

View File

@@ -20,6 +20,7 @@ namespace NodeCanvas.Tasks.Actions {
private Vector3 velocityOnStart; private Vector3 velocityOnStart;
private Vector3 directionOnStart; private Vector3 directionOnStart;
private Vector3 originalDirection; private Vector3 originalDirection;
private Vector3 locationOnStart;
public float speed; public float speed;
public float minDistance; public float minDistance;
@@ -55,9 +56,16 @@ namespace NodeCanvas.Tasks.Actions {
//Call EndAction() to mark the action as finished, either in success or failure. //Call EndAction() to mark the action as finished, either in success or failure.
//EndAction can be called from anywhere. //EndAction can be called from anywhere.
protected override void OnExecute(){ protected override void OnExecute(){
// Some startup stuff
camera = Camera.main.transform; camera = Camera.main.transform;
MonoManager.current.onLateUpdate += DrawGrappleGizmo; MonoManager.current.onLateUpdate += DrawGrappleGizmo;
// Set the initial direction MonoManager.current.onLateUpdate += UpdateLineRenderer;
// Add the renderer
agent.gameObject.AddComponent<LineRenderer>();
// Set original direction and locoation
locationOnStart = agent.transform.position;
directionOnStart = agent.transform.position.DirectionTo(grapplePoint.value); directionOnStart = agent.transform.position.DirectionTo(grapplePoint.value);
// Get the current move direction // Get the current move direction
@@ -174,6 +182,7 @@ namespace NodeCanvas.Tasks.Actions {
agent.SetNewGravity(finalDirection.y); agent.SetNewGravity(finalDirection.y);
agent.SmoothToSpeed(speed, 25f * Time.deltaTime); agent.SmoothToSpeed(speed, 25f * Time.deltaTime);
// Calculate dot products for using to end the action // Calculate dot products for using to end the action
float xzDot = Vector3.Dot(-directionOnStart.Flatten(null, 0).normalized, -directionToPoint.Flatten(null, 0).normalized); float xzDot = Vector3.Dot(-directionOnStart.Flatten(null, 0).normalized, -directionToPoint.Flatten(null, 0).normalized);
float yDot = Vector3.Dot( // This one has to be rotated around the XZ float yDot = Vector3.Dot( // This one has to be rotated around the XZ
@@ -250,6 +259,23 @@ namespace NodeCanvas.Tasks.Actions {
return targetSwingDirection.normalized; return targetSwingDirection.normalized;
} }
public void UpdateLineRenderer(){
// Update the Line Renderer
var lr = agent.GetComponent<LineRenderer>();
lr.positionCount = 2;
// Very shoddy position setting
lr.SetPositions(new []{
agent.transform.position,
grapplePoint.value}
);
lr.startWidth = .1f;
lr.endWidth = .1f;
}
public void DrawGrappleGizmo(){ public void DrawGrappleGizmo(){
// Destination gizmos // Destination gizmos
using (Draw.WithColor(Color.blue)){ using (Draw.WithColor(Color.blue)){
@@ -320,7 +346,6 @@ namespace NodeCanvas.Tasks.Actions {
Draw.SolidTriangle(vertArrowUpPosition + camera.rotation * Vector3.left/4, vertArrowUpPosition + Vector3.up/2, vertArrowUpPosition + camera.rotation * Vector3.right/4); Draw.SolidTriangle(vertArrowUpPosition + camera.rotation * Vector3.left/4, vertArrowUpPosition + Vector3.up/2, vertArrowUpPosition + camera.rotation * Vector3.right/4);
} else { } else {
Draw.SolidTriangle(vertArrowDownPosition + camera.rotation * Vector3.left/4, vertArrowDownPosition + Vector3.down/2, vertArrowDownPosition + camera.rotation * Vector3.right/4); Draw.SolidTriangle(vertArrowDownPosition + camera.rotation * Vector3.left/4, vertArrowDownPosition + Vector3.down/2, vertArrowDownPosition + camera.rotation * Vector3.right/4);
} }
} }
} }
@@ -328,6 +353,9 @@ namespace NodeCanvas.Tasks.Actions {
//Called when the task is disabled. //Called when the task is disabled.
protected override void OnStop() { protected override void OnStop() {
MonoManager.current.onLateUpdate -= DrawGrappleGizmo; MonoManager.current.onLateUpdate -= DrawGrappleGizmo;
MonoManager.current.onLateUpdate -= UpdateLineRenderer;
GameObject.Destroy(agent.gameObject.GetComponent<LineRenderer>());
} }
//Called when the task is paused. //Called when the task is paused.