private void moveKinematic() { if (Input.GetMouseButtonDown(0)) { destination = DirectionUtility.getMouseDirection(); destination.y = transform.position.y; go = true; calculating = true; inizializeTree(destination); draw.clean(); } else { if (go && path.Count > 0) { destination = (Vector3)path[path_index]; float d = Vector3.Distance(transform.position, destination); if (d > 0.5) { Vector3 direction = (destination - transform.position).normalized; DirectionUtility.makeKinematicMove(rigidbody, direction, speed); } else { rigidbody.velocity = Vector3.zero; transform.position = destination; path_index++; if (path_index == path.Count) { go = false; path_index = 0; } } } } }
private void moveKinematic() { if (Input.GetMouseButtonDown(0)) { destination = DirectionUtility.getMouseDirection(); destination.y = transform.position.y; go = true; draw.clean(); path_index = 2; calculating = true; inizializeTree(transform.position, destination); } else { if (go && path.Count > 0) { Vector3 dest = (Vector3)path[path_index]; //Debug.Log(path.Count+" "+path_index+" "+path[path_index]); //makeMove(dest); float d = Vector3.Distance(transform.position, dest); if (d > 1f) { Vector3 direction = (dest - transform.position).normalized; //correctAngle(direction); //DirectionUtility.makeKinematicMove (rigidbody, direction, speed); DirectionUtility.makeCarMove(rigidbody, transform, direction, speed); } else { rigidbody.velocity = Vector3.zero; //transform.position = dest; //Debug.Log(path.Count+" "+path_index); path_index++; if (path_index == path.Count) { go = false; } } } } }
void Update() { if (Input.GetMouseButtonDown(0)) { destination = DirectionUtility.getMouseDirection(); destination.y = transform.position.y; calcPath = true; } if (calcPath) { calcPath = false; go = true; path = car.RSR(transform.position, transform.forward, destination); draw.drawMultipleLines(path, Color.magenta); if (free(path)) { return; } path = car.LSR(transform.position, transform.forward, destination); draw.drawMultipleLines(path, Color.magenta); if (free(path)) { return; } path = car.LSL(transform.position, transform.forward, destination); draw.drawMultipleLines(path, Color.magenta); if (free(path)) { return; } path = car.RSL(transform.position, transform.forward, destination); draw.drawMultipleLines(path, Color.magenta); if (free(path)) { return; } go = false; } else if (go && path.Count > 0) { destination = (Vector3)path[path_index]; float d = Vector3.Distance(transform.position, destination); if (d > 2) { Vector3 direction = (destination - transform.position).normalized; correctAngle(direction); DirectionUtility.makeKinematicMove(rigidbody, direction, speed); } else { rigidbody.velocity = Vector3.zero; transform.position = destination; path_index++; if (path_index == path.Count) { go = false; path_index = 1; } } } }