added: rudimentary grapple line renderer
This commit is contained in:
@@ -20,6 +20,7 @@ namespace NodeCanvas.Tasks.Actions {
|
||||
private Vector3 velocityOnStart;
|
||||
private Vector3 directionOnStart;
|
||||
private Vector3 originalDirection;
|
||||
private Vector3 locationOnStart;
|
||||
|
||||
public float speed;
|
||||
public float minDistance;
|
||||
@@ -55,9 +56,16 @@ 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(){
|
||||
// Some startup stuff
|
||||
camera = Camera.main.transform;
|
||||
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);
|
||||
|
||||
// Get the current move direction
|
||||
@@ -174,6 +182,7 @@ namespace NodeCanvas.Tasks.Actions {
|
||||
agent.SetNewGravity(finalDirection.y);
|
||||
agent.SmoothToSpeed(speed, 25f * Time.deltaTime);
|
||||
|
||||
|
||||
// Calculate dot products for using to end the action
|
||||
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
|
||||
@@ -250,6 +259,23 @@ namespace NodeCanvas.Tasks.Actions {
|
||||
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(){
|
||||
// Destination gizmos
|
||||
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);
|
||||
} else {
|
||||
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.
|
||||
protected override void OnStop() {
|
||||
MonoManager.current.onLateUpdate -= DrawGrappleGizmo;
|
||||
MonoManager.current.onLateUpdate -= UpdateLineRenderer;
|
||||
|
||||
GameObject.Destroy(agent.gameObject.GetComponent<LineRenderer>());
|
||||
}
|
||||
|
||||
//Called when the task is paused.
|
||||
|
||||
Reference in New Issue
Block a user