public void Start() { const float weebleHeightOffset = 1.1f; foreach (Transform weebleTransform in GameObject.Find("Agents/Weebles").transform) { if (World.Instance != null) { MovingEntity movingEntity = weebleTransform.GetComponent <MovingEntity>(); if (movingEntity != null) { PathManager pathManager = weebleTransform.GetComponent <PathManager>(); if (pathManager != null) { SearchSpace searchSpace = pathManager.searchSpace; if (searchSpace != null) { weebleTransform.position = movingEntity.PositionAt(searchSpace.GetRandomEntityPosition()); } else { weebleTransform.position = movingEntity.PositionAt(World.Instance.GetRandomEntityPosition(movingEntity)); } } else { weebleTransform.position = movingEntity.PositionAt(World.Instance.GetRandomEntityPosition(movingEntity)); } } else { weebleTransform.position = World.Instance.GroundPositionAt(World.Instance.GetRandomPosition(), weebleHeightOffset); } } else { weebleTransform.position = Vector3.up * weebleHeightOffset; } } }
public bool Traverse(PathEdge edgeToFollow, bool brakeOnApproach, bool stopOnArrival) { if ((movingEntity == null || !movingEntity.enabled) && (aiController == null || !aiController.enabled)) { return(false); } // Seek must exist and not be active if (seek == null || seek.TargetPosition.HasValue) { return(false); } // Arrive must exist and not be active if (arrive == null || arrive.TargetPosition.HasValue) { return(false); } seek.enabled = seek.isOn = false; arrive.enabled = arrive.isOn = false; EdgeToFollow = edgeToFollow; if (brakeOnApproach) { if (steering != null) { steering.enabled = steering.isOn = false; } steering = arrive; steering.TargetPosition = (movingEntity != null && movingEntity.enabled) ? movingEntity.PositionAt(EdgeToFollow.Destination) : World.Instance.GroundPositionAt(EdgeToFollow.Destination); steering.enabled = steering.isOn = true; if ((movingEntity == null || !movingEntity.enabled) && aiController != null && aiController.enabled) { aiController.SetSteering(steering); } } else { if (steering != null) { steering.enabled = steering.isOn = false; } steering = seek; steering.TargetPosition = (movingEntity != null && movingEntity.enabled) ? movingEntity.PositionAt(EdgeToFollow.Destination) : World.Instance.GroundPositionAt(EdgeToFollow.Destination); steering.enabled = steering.isOn = true; if ((movingEntity == null || !movingEntity.enabled) && aiController != null && aiController.enabled) { aiController.SetSteering(steering); } } return(true); }