// Initialize path override protected void LocalStart() { // Setting state options DynamicPointState.lo = lowLimitRRT; DynamicPointState.hi = highLimitRRT; DynamicPointState.maxAcc = maxAcceleration; DynamicPointState.heuristic = heuristic; DynamicPointState.hParam = hParam; // Set states with zero initial velocity and run rrt startState = new DynamicPointState( startPos.x, startPos.y, Vector3.zero); goalState = new DynamicPointState( goalPos.x, goalPos.y, Vector3.zero); DynamicPointState.goalState = goalState; rrt = new RRT <DynamicPointState>( startState, goalState, DynamicPointState.GenerateRandom, polys, iterations, neighborhood ); // Remove the last move in the list and replace it with breaking DynamicPointMove last = rrt.moves[rrt.moves.Count - 1] as DynamicPointMove; Vector3 lastVel = last.velocity; float lastTime = lastVel.magnitude / maxAcceleration; Move lastMove = new DynamicPointMove(lastVel, -lastVel.normalized * maxAcceleration, lastTime); moves = new Stack <Move>( Enumerable.Concat( new Move[] { lastMove }, Enumerable.Reverse(rrt.moves).Skip(1) ) ); // Set times cost = rrt.cost + lastTime - last.t; rrtTime = rrt.runTime; Debug.Log("Time: " + cost + " RRT: " + rrtTime); }
// Initializes and runs rrt override protected void LocalStart() { // Setting state options DynamicCarState.maxAcc = maxAcc; DynamicCarState.maxPhi = maxPhi; DynamicCarState.L = L; DynamicCarState.r = L / Mathf.Tan(maxPhi * Mathf.PI / 180); DynamicCarState.lo = lowLimitRRT; DynamicCarState.hi = highLimitRRT; DynamicCarState.timeStep = time; // Set scale and rotate to right transform.localScale = new Vector3(1, 1, L); transform.rotation = Quaternion.Euler(0, 90, 0); // Create states, rotation is right startState = new DynamicCarState(startPos.x, startPos.y, Vector3.right, 0); goalState = new DynamicCarState(goalPos.x, goalPos.y, Vector3.right, 0); // Run rrt rrt = new RRT <DynamicCarState>( startState, goalState, DynamicCarState.GenerateRandom, polys, iterations, neighborhood ); // Remove the last move in the list and replace it with breaking DynamicCarMove last = rrt.moves[rrt.moves.Count - 1] as DynamicCarMove; Vector3 lastVel = last.velocity; float lastTime = last.speed / maxAcc; Move lastMove = new DynamicPointMove(lastVel * last.speed, -lastVel.normalized * maxAcc, lastTime); moves = new Stack <Move>( Enumerable.Concat( new Move[] { lastMove }, Enumerable.Reverse(rrt.moves).Skip(1) ) ); // Set moves and other data needed for base cost = rrt.cost + lastTime - last.t; rrtTime = rrt.runTime; Debug.Log("Time: " + cost + " RRT: " + rrtTime); // This part generates points for realistic path GameObject tmp = new GameObject(); Transform tr = tmp.transform; tr.position = transform.position; tr.rotation = transform.rotation; List <Move> tmpMoves = new List <Move>(); foreach (Move m in rrt.moves) { tmpMoves.Add(m.Copy()); } foreach (Move m in tmpMoves) { while (m.t > 0) { m.MoveMe(tr, 0.1f); poss.Add(tr.position); } } Destroy(tmp); }