private void FixedUpdate() { // Não precisa chegar se é localplayer aqui, pois _input nunca será setado. // Checa se há input. if (_input.sqrMagnitude > 0f) { // Converte a direção da input em um ângulo, levando em consideração a orientação isométrica. float targetRotation = Mathf.Atan2(_input.x + _input.y, _input.y - _input.x) * Mathf.Rad2Deg; // Faz uma interpolação suavizada para a rotação, passando a ideia de aceleração. transform.eulerAngles = Vector3.up * Mathf.SmoothDampAngle(transform.eulerAngles.y, targetRotation, ref _turnSmoothVelocity, this.turnAccelerationTime, Mathf.Infinity, Time.fixedDeltaTime); // Determina o Vetor de velocidade. _currentVelocity = (transform.forward * _currentSpeed * Time.fixedDeltaTime) + Physics.gravity; // Aplica a velocidade encontrada no componente CharacterController. _controller.Move(_currentVelocity); // TODO: ao caminar, executar ordem de seguir? NetworkHero.GetInstance().SendFollow(); } else { if (isLocalPlayer) { // Se não houver input, aplica apenas a gravidade no componente CharacterController. _controller.Move(Physics.gravity); } } }
// ▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀ // Métodos Privados. // Awake is called when the script instance is being loaded private void Start() { // Inicializa referências de componentes, e Hashs para animação. _animator = GetComponent <Animator>(); _controller = GetComponent <CharacterController>(); _animSpeedHash = Animator.StringToHash("Speed"); _networkHero = GetComponent <NetworkHero>(); if (isLocalPlayer) { _mainCamera = Camera.main; _mainCamera.GetComponent <CameraController>().target = this.transform; } }
public static NetworkHero SetUpEnemyHero(RawHeroInfo rInfo) { GameObject heroObj = CreateHeroByType(rInfo.type); heroObj.name += "Net"; NetworkHero hero = heroObj.AddComponent <NetworkHero>(); heroObj.AddComponent <CustomStrategy> (); heroObj.AddComponent <SimpleAnim> (); hero.Init(rInfo); hero.GetHeroInfo().Direction = rInfo.direction; hero.GetHeroInfo().TeamColor = TeamColor.Red; return(hero); }
// ▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀ // Update is called once per frame void Update() { // Recebe a input _input.Set(/*Input.GetAxis("Xbox RHorizontal")*/ InputManager.GetSelectorHorizontalAxis(), /*Input.GetAxis("Xbox RVertical")*/ InputManager.GetSelectorVerticalAxis()); // Isso aqui precisa vir do GameManager. if (_input.sqrMagnitude > 0.0f) { // Calcula a direção do input, considerando a perspectiva isométrica. _input = Vector2.ClampMagnitude(_input, 1f); // Calcula movimento e direção. Vector3 direction = Quaternion.Euler(30.0f, 45.0f, 0.0f) * new Vector3(_input.x, 0f, _input.y); direction *= Time.deltaTime * movimentSpeed; // TODO: Bug Conhecido. direction = ClampToScreen(direction); direction.y = (NetworkSelectorRaycaster.surfaceHeight - direction.y); _selector.Translate(direction, Space.World); Vector3 temp = _selector.position; if (temp.y < 0f) { temp.y = 0; } _selector.position = temp; } _leftTrigger = /*Input.GetAxis("Xbox RLTrigger") < 0.0f*/ InputManager.GetCancelTrigger(); _rightTrigger = /*Input.GetAxis("Xbox RLTrigger") > 0.0f*/ InputManager.GetActionTrigger(); if (_leftTrigger) { NetworkHero.GetInstance().DeSelect(); } if (_rightTrigger) { NetworkHero.GetInstance().SetAction(_selector.position); } }
private void FixedUpdate() { /* Por razões de performance, optamos por utilizar strucs (memória Stack), mandetendo a politica * de tolerancia zero de alocação de memória em Loops. */ surfaceHeight = 0.0f; SetOriginHitPoint(); RaycastHit hit; if (Physics.Raycast(origin, -Vector3.up, out hit, heightOffset)) { if (hit.collider.gameObject.layer == _physicsEnvironmentLayer) { surfaceHeight = hit.point.y - this.transform.position.y; } NetworkSelectorHitState hitState = new NetworkSelectorHitState(); NavMeshHit navHit; NavMesh.Raycast(hit.point, hit.point - Vector3.up, out navHit, NavMesh.AllAreas); if (navHit.mask == 1 << _navMeshWalkableLayer) { Collider[] hitColliders = Physics.OverlapSphere(this.transform.position, 1.8f, 1 << _physicsEntityLayer); if (hitColliders.Length > 0) { int alliesCount = 0; int opponentsCount = 0; int[] alliesIndexs = new int[5]; int[] opponentsIndexs = new int[5]; NetworkDinamicEnity[] entity = new NetworkDinamicEnity[hitColliders.Length]; for (int i = 0; i < hitColliders.Length; i++) { entity[i] = hitColliders[i].gameObject.GetComponent <NetworkDinamicEnity>(); Assert.IsFalse(entity[i] == null); // Se alguma coisa errada estiver na layer Entity if (entity[i].entityClan == NetworkHero.EntityClan) { alliesIndexs[alliesCount] = i; ++alliesCount; } else { opponentsIndexs[alliesCount] = i; ++opponentsCount;; } } hitState.allies = new NetworkDinamicEnity[alliesCount]; for (int i = 0; i < alliesCount; i++) { hitState.allies[i] = entity[alliesIndexs[i]]; } hitState.opponent = new NetworkDinamicEnity[opponentsCount]; for (int i = 0; i < opponentsCount; i++) { hitState.opponent[i] = entity[opponentsIndexs[i]]; } if (opponentsCount > 0) { hitState.selectorState = (int)SelectorStateType.Opponent; } else { hitState.selectorState = (int)SelectorStateType.Valid; } } } else { hitState.selectorState = (int)SelectorStateType.Invalid; } if (hitState.allies == null) { hitState.allies = new NetworkDinamicEnity[0]; } if (hitState.opponent == null) { hitState.opponent = new NetworkDinamicEnity[0]; } NetworkHero.GetInstance().SetSelectorState(hitState); } }
// This is invoked on behaviours that have authority, based on context and the LocalPlayerAuthority value on the NetworkIdentity public override void OnStartAuthority() { // Instancia única é garantida apenas no GameObject que possui LocalPlayerAuthority. _instance = this; }