public void Start() { controller = go.GetComponent<CharacterController>(); controller2 = go.GetComponent<RVOController>(); if (controller == null && controller2 == null) { if(AstarPath.HasPro) { controller2 = go.AddComponent<RVOController>(); controller2.Move(new Vector3(0,0,0)); } else { controller = go.AddComponent<CharacterController>(); } } UpdatePath(); }
public override void OnEnter() { if(moveMode == MoveMode.followPath) { path = FsmConverter.GetPath(inputPath); if(path == null) { if(LogEvents.Value) { Debug.Log("Astar Follow Path failed. The path is null"); } Fsm.Event(failedEvent); Finish(); return; } else if(path.vectorPath.Count == 0) { if(LogEvents.Value) { Debug.Log("Astar Follow Path failed. The path contains no nodes"); } Fsm.Event(failedEvent); Finish(); return; } } currentWaypoint = 0; go = actor.OwnerOption == OwnerDefaultOption.UseOwner ? Owner : actor.GameObject.Value; if( go == null) { if(LogEvents.Value) { Debug.Log("Astar Move To failed. The actor is null"); } Fsm.Event(failedEvent); Finish(); return; }//finish the action if any of the requirements are not met controller = go.GetComponent<CharacterController>(); controller2 = go.GetComponent<RVOController>(); rigidbody = go.GetComponent<Rigidbody>(); if(controllerType == ControllerType.characterController && controller == null) { controller = go.AddComponent<CharacterController>(); } else if(controllerType == ControllerType.rvoController && controller2 == null) { if(AstarPath.HasPro) { controller2 = go.AddComponent<RVOController>(); controller2.Move(new Vector3(0,0,0)); } else { controllerType = ControllerType.characterController;//free version can't use RVOControllers if(controller == null) { controller = go.AddComponent<CharacterController>(); } } } else if(controllerType == ControllerType.rigidbody && rigidbody == null) { rigidbody = go.AddComponent<Rigidbody>(); rigidbody.drag = 0.5f; rigidbody.freezeRotation = true; } else if(controllerType == ControllerType.rigidbodyVelocity && rigidbody == null) { rigidbody = go.AddComponent<Rigidbody>(); rigidbody.freezeRotation = true; } if(moveMode != MoveMode.followPath) { CalculatePath(); } if(moveMode == MoveMode.followPath && !startAtStart.Value) { currentWaypoint = getClosest(); } if(moveMode == MoveMode.followPath && connectPath.Value) { done = false; ConnectPathX(); } }