Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Local Avoidance with splines and colliders.
#1
Im opening this thread as a kind of ongoing discussion about using curvy for local avoidance for AI.

The avoidance is for a spaceship type behaviour, with a limit on turn rates depending on the maneuverability and momentum of the ship. 
Im thinking of a way to project the spline in front of the ship's path, and detecting impending collisions (im thinking clonebuilder colliders that send info to their closest CV).

What i want, optimally, is a accurate ten second projection of where the ship will move, that adjusts when it detects collisions before they happen, and attempts to avoid it.

Anyone done something similar, or have some tips regarding doing something like this? Thanks.
Reply
#2
So i'm revisiting trying to use curves for 3Dpathfinding/avoidance, and i've got it setting smooth/safe paths for my AI ships.
There are a few cases that i'd like some help with:

1: The distance to the destination is too small, and it crams a bunch of CV's into a small area at weird positions, causing the path to get squiggly.

2: The destination is behind my ship. so the first major bend gets increasingly sharp, no matter how much i scale the handles

[Image: Cf2DLyj.png]
3: I'm limiting the up/down rotation of the ships, so figuring out a minimum turn radius, and constructing a Y directional spiral to allow the ships to move up towards their desired height, before continuing along their X/Z plane.

Any suggestions?
Reply
#3
Thumbs Down 
    So I've managed to build my curve to my liking, now i want to insert/remove CP's along the curve, to make it path around collisions.

I have the collisions working, but when i try to add/remove CP's, i screw up the order, and can't find a reliable way of figuring out what CP's to remove, and when to add.

PseudoCode wise:
Raycast 20 times along curve
if hit: add CP1 at hit point
if another CPx is too close, remove that CPx
Check areas around the hit point, move CP1 to an open area
continue down the curve

I Get all this working, but the CP1 ends up at the end of the Segment list, even if i set it to spawn after the closest point.


      Part of the code handling adding/removing

Code:
int raycastResolution = 20;
float segmentLength = splineTotalDist/raycastResolution;


for(int i = 0; i<=raycastResolution; i++)
{
if(i!=raycastResolution)
{
thisInterp = spline.InterpolateByDistance(i*splineTotalDist/raycastResolution*1f);
nextInterp = spline.InterpolateByDistance((i+1f)*splineTotalDist/raycastResolution*1f);
//float tFdistance = spline.TFToDistance();
// float mag = (nextInterp-thisInterp).magnitude;
Ray interpolationRay = new Ray(thisInterp, (nextInterp-thisInterp));
RaycastHit hit;
// Debug.Log (interpolationRay.origin + " " + interpolationRay.direction*10+" Satan is real");

//If Sphere hits something
Debug.DrawRay(interpolationRay.origin, interpolationRay.direction*segmentLength, Color.magenta, 30);
if(Physics.SphereCast(interpolationRay,width*0.5f,out hit,segmentLength,rayCastMask))
// if(Physics.Raycast(interpolationRay,out hit, segmentLength*1.1f, rayCastMask))
{

float closestInterpPoint = spline.GetNearestPointTF(hit.point);


// Debug.Log (hit.point);
Debug.DrawRay(spline.Interpolate(closestInterpPoint), Vector3.up*5, Color.magenta, 45);
//TODO Add detection for if there are no Controlpoints nearby, create one and edit the curve.

Color ccTYpe = Color.white;
CurvySplineSegment oldSegment = spline.TFToSegment(closestInterpPoint);
CurvySplineSegment cc = spline.Add (oldSegment);

//Grab the previous segment if there was no next segment
// if(oldSegment==null)
// {
// oldSegment = spline.PreviousSegment(spline.TFToSegment(closestInterpPoint));
// cc
// }
// else
// cc = spline.Add (true, oldSegment);

cc.Position = hit.point;

if(oldSegment!=null)
{
float distanceToClosestCC = Mathf.Abs(closestInterpPoint-oldSegment.LocalFToTF(0));
// Debug.Log (distanceToClosestCC + "Is this distance to closest CC");

//if the distance to the precviousCVis less than 35 units, delete
if(distanceToClosestCC<0.25f)
{
Debug.DrawRay(oldSegment.Position, Vector3.up*5, Color.black, 30);

cc.ConnectTo(oldSegment.PreviousControlPoint);
cc.ConnectTo(oldSegment.NextControlPoint);
oldSegment.ClearConnections();
oldSegment.Delete();
}
//
// spline.RefreshImmediately();
//Debug.DrawRay(cc.Position, Vector3.up*5,ccTYpe);

}
//Debug.DrawRay(cc.Position, Vector3.up*5, Color.yellow, 45);
Vector3 newPosition = FindOpenSpace(cc);
cc.Position = newPosition;
}
else
Debug.DrawRay(interpolationRay.origin, interpolationRay.direction*segmentLength, Color.green, 30);
}
}
Reply
#4
Would you mind to register to 2.0 beta (see sticky post above) and try this with the new version? Internal CP handling has fundamentally changed. Curvy 2.0 RC1 is coming very close, so initial development is close to end and it's already usable. I doubt you would like to switch back to Curvy 1 once you got used to Curvy 2.
Reply
#5
Sure, ill give it a go.
(06-10-2015, 07:52 AM)'Jake' Wrote: Would you mind to register to 2.0 beta (see sticky post above) and try this with the new version? Internal CP handling has fundamentally changed. Curvy 2.0 RC1 is coming very close, so initial development is close to end and it's already usable. I doubt you would like to switch back to Curvy 1 once you got used to Curvy 2.

 



 
Reply


Possibly Related Threads…
Thread Author Replies Views Last Post
  snap to the curve created by the curvy splines segment points ShiroeYamamoto 0 0 1 hour ago
Last Post: ShiroeYamamoto
Bug Changing spline connection in inspector causes splines to revert to defaults lacota 3 6 03-18-2024, 07:55 PM
Last Post: _Aka_
  Using Unity's SplineContainer in Curvy Splines dlees9191 3 15 02-26-2024, 09:49 AM
Last Post: _Aka_
  Distance travelled across multiple splines jh092 1 7 02-23-2024, 09:44 AM
Last Post: _Aka_

Forum Jump: