/// <summary> /// Move the clone. /// </summary> /// <param name="i"> ID of the joystic that is going to move this player. </param> /// <param name="controller"> CharacterController of clone. </param> public void MoveClone(ref int i, GameObject clone) { if (clone != null) { CharacterController controllerClone = clone.GetComponent <CharacterController>(); if (usingKeyboard) { movementClone = new Vector3(Input.GetAxis("Horizontal"), 0f, Input.GetAxis("Vertical")); //Setando movimentação } else { movementClone = new Vector3(UNInput.GetAxis(i, "Right Stick Horizontal"), 0f, UNInput.GetAxis(i, "Right Stick Vertical")); //Setando movimentação } if (movementClone.magnitude < 0.2f) //Se a movementação for pequena(correção do analógico) { movementClone = Vector3.zero; //Zerando movimentação } else { clone.transform.rotation = Quaternion.identity * Quaternion.LookRotation(movementClone, Vector3.up); //Atualizando a rotação } gravity += Vector3.down * forceGravity * Time.deltaTime; //Adicionando a gravidade controllerClone.Move(((clone.transform.rotation * Vector3.forward * currentSpeed) * movementClone.magnitude * Time.deltaTime) + (gravity * Time.deltaTime)); //Movimentando if (gravity.y < -forceGravity) //Se a gravidade for maior que a força gravitacional { gravity = Vector3.down * forceGravity; //Setando o valor máximo da gravidade } } // else // GetComponent<PlayerPickup>().usingClone = false; }
void Axes(int id, Gamepad game) { //Values game.l3X = UNInput.GetAxis(id, AxisCode.LSH); game.l3Y = UNInput.GetAxis(id, AxisCode.LSV); game.r3X = UNInput.GetAxis(id, AxisCode.RSH); game.r3Y = UNInput.GetAxis(id, AxisCode.RSV); game.l2_ = UNInput.GetAxis(id, AxisCode.LT); game.r2_ = UNInput.GetAxis(id, AxisCode.RT); //Left Stick if (game.l3X != 0 || game.l3Y != 0) { game.l3Stick.transform.localPosition = new Vector3(game.l3X * 25f, game.l3Y * 25f, 0f); } else { game.l3Stick.transform.localPosition = Vector3.zero; } //Right Stick if (game.r3X != 0 || game.r3Y != 0) { game.r3Stick.GetComponent <RectTransform>().localPosition = new Vector3(game.r3X * 25f, game.r3Y * 25f, 0f); } else { game.r3Stick.GetComponent <RectTransform>().localPosition = Vector3.zero; } //Left Trigger if (game.l2_ != 0) { game.l2GO.transform.localPosition = new Vector3(game.l2GO.transform.localPosition.x, 220f + (-game.l2_ * 45f), 0f); game.l2GO.GetComponent <Image>().color = game.l2; } else { game.l2GO.transform.localPosition = new Vector3(game.l2GO.transform.localPosition.x, 220f, 0f); game.l2GO.GetComponent <Image>().color = Color.white; } //Right Trigger if (game.r2_ != 0) { game.r2GO.GetComponent <RectTransform>().localPosition = new Vector3(game.r2GO.transform.localPosition.x, 220f + (game.r2_ * -45f), 0f); game.r2GO.GetComponent <Image>().color = game.r2; } else { game.r2GO.GetComponent <RectTransform>().localPosition = new Vector3(game.r2GO.transform.localPosition.x, 220f, 0f); game.r2GO.GetComponent <Image>().color = Color.white; } //Texts game.l3XText.text = "H: " + game.l3X.ToString("F1"); game.l3YText.text = "V: " + game.l3Y.ToString("F1"); game.r3XText.text = "H: " + game.r3X.ToString("F1"); game.r3YText.text = "V: " + game.r3Y.ToString("F1"); game.l2Text.text = game.l2_.ToString("F1"); game.r2Text.text = game.r2_.ToString("F1"); }
protected override void Update() { base.Update(); m_MovementInputValue = (m_MovementInputValue == 0) ? UNInput.GetAxis(m_PlayerNumber, _networkVerticalAxis) : m_MovementInputValue; m_TurnInputValue = (m_TurnInputValue == 0) ? UNInput.GetAxis(m_PlayerNumber, _networkHorizontalAxis) : m_TurnInputValue; if (Input.GetButtonDown(_placeAmpButton) || UNInput.GetButtonDown(m_PlayerNumber, "Action")) { Debug.LogFormat("Player {0} placed an Amp!", m_PlayerNumber); PlaceAmp(); } if (Input.GetKeyDown(KeyCode.Backspace) || UNInput.GetButtonDown(m_PlayerNumber, "Start")) { for (int i = _amps.Count - 1; i >= 0; i--) { var a = _amps[i]; DestroyAmp(a); } _amps.Clear(); } var enemyAmps = GameController.Instance.EnemyAmps(_player); AmpController target = null; var minDist = float.MaxValue; foreach (var a in enemyAmps) { Vector3 point; var dist = a.PowLine.SqrDistanceFromPoint(_transform.position, out point); if (dist < MaxCutSqrDistance && dist < minDist) { minDist = dist; Debug.DrawLine(point, point + Vector3.up * 100f, Color.yellow); target = a; } } if (target != null && Input.GetButton(_cutButton) || UNInput.GetButton(m_PlayerNumber, "Back")) { target.Owner.DestroyAmp(target); } }
void Update() { if (useKeyboard) { tempH = Input.GetKeyDown(KeyCode.D) || Input.GetKeyDown(KeyCode.RightArrow) ? 1 : Input.GetKeyDown(KeyCode.A) || Input.GetKeyDown(KeyCode.LeftArrow) ? -1 : 0; tempV = Input.GetKeyDown(KeyCode.W) || Input.GetKeyDown(KeyCode.UpArrow) ? 1 : Input.GetKeyDown(KeyCode.S) || Input.GetKeyDown(KeyCode.DownArrow) ? -1 : 0; action = Input.GetKeyDown(KeyCode.Space) || Input.GetKeyDown(KeyCode.X); } else { tempH = UNInput.GetAxis(joystickId, AxisCode.LSH); tempV = UNInput.GetAxis(joystickId, AxisCode.LSV); action = UNInput.GetButtonDown(joystickId, ButtonCode.A) || UNInput.GetButtonDown(joystickId, ButtonCode.RightBumper); } if (Mathf.Abs(tempH) > controlRate) { if (tempH > 0) { movement.ChangeDirection(Direction.Right); } else { movement.ChangeDirection(Direction.Left); } } else if (Mathf.Abs(tempV) > controlRate) { if (tempV > 0) { movement.ChangeDirection(Direction.Top); } else { movement.ChangeDirection(Direction.Bottom); } } if (action) { elementBending.Action(); } }
public void Movement() { if (Time.time < delay) { return; } movement.x = UNInput.GetAxis(playerData.ID, AxisCode.LeftStickHorizontal); movement.y = UNInput.GetAxis(playerData.ID, AxisCode.LeftStickVertical); transform.rotation = Quaternion.LookRotation( new Vector3( movement.x, 0.0f, movement.y ), Vector3.up ); if (controller.isGrounded) { moveDirection = new Vector3( Mathf.Abs(movement.x) > .4f ? movement.x : 0f, 0.0f, Mathf.Abs(movement.y) > .4f ? movement.y : 0f); //moveDirection = transform.TransformDirection(moveDirection); moveDirection = moveDirection.normalized * playerData.speed; } // Apply gravity moveDirection.y = moveDirection.y - (playerData.gravity * Time.deltaTime); // Move the controller controller.Move(moveDirection * Time.deltaTime); //transform.rotation = Quaternion.LookRotation(moveDirection, Vector3.up); //if (catchBlock) //{ // catchBlock.transform.position = new Vector3(transform.position.x, 4f, transform.position.z); //} }
private void Update() { if (UNInput.GetButtonDown(ButtonCode.Start)) { if (playersActivated.Count > 0) { SceneManager.LoadScene(1); } } for (int id = 0; id < 4; id++) { if (playersActivated.Contains(id)) { horizontal = UNInput.GetAxis(players[id].playerData.ID, AxisCode.LeftStickHorizontal); vertical = UNInput.GetAxis(players[id].playerData.ID, AxisCode.LeftStickVertical); if (Mathf.Abs(horizontal) > .55f) { if (horizontal > 0f) { players[id].IncrementModel(); } else { players[id].DecrementModel(); } } if (Mathf.Abs(vertical) > .55f) { if (vertical > 0f) { players[id].IncrementSkin(); } else { players[id].DecrementSkin(); } } continue; } blockCheck = false; if (UNInput.GetButtonDown(id, ButtonCode.B)) { for (int i = 0; i < 4; i++) { if (players[i].IsActive()) { continue; } menuController.ChooseToMenu(); Invoke("Start", 1f); blockCheck = true; break; } } if (UNInput.GetButtonDown(id, ButtonCode.A)) { for (int i = 0; i < 4; i++) { if (players[i].IsActive()) { continue; } players[i].ActivePlayer(id, false); playersActivated.Add(id); blockCheck = true; break; } } if (blockCheck) { break; } } }
/// <summary> /// Move the player. /// </summary> /// <param name="i"> id of the joystic that is going to move this player. </param> public void Move(int i) { if (canMove)//Se o jogador pode se movimentar { if (usingKeyboard) { movement = Vector3.zero; if (Input.GetKey(KeyCode.UpArrow) || Input.GetKey(KeyCode.W)) { movement += Vector3.forward; } if (Input.GetKey(KeyCode.DownArrow) || Input.GetKey(KeyCode.S)) { movement += Vector3.back; } if (Input.GetKey(KeyCode.LeftArrow) || Input.GetKey(KeyCode.A)) { movement += Vector3.left; } if (Input.GetKey(KeyCode.RightArrow) || Input.GetKey(KeyCode.D)) { movement += Vector3.right; } //Setando movimentação } else { movement = new Vector3(UNInput.GetAxis(i, AxisCode.LSH), 0f, UNInput.GetAxis(i, AxisCode.LSV)); //Setando movimentação } if (movement.magnitude < 0.2f) //Se a movementação for pequena(correção do analógico) { movement = Vector3.zero; //Zerando movimentação } else { transform.rotation = Quaternion.identity * Quaternion.LookRotation(movement, Vector3.up); //Atualizando a rotação } if (controller.isGrounded) //Se estiver colidindo com o chão { doubleJumping = false; //Pode pular a segunda vez if (canJump) //Se pode pular { if (UNInput.GetButtonDown(i, ButtonCode.A) || (Input.GetKeyDown(KeyCode.KeypadEnter) && usingKeyboard)) //Se o jogador apertar o botão de pulo { Jump(); //Função de pulo } } } else //Se não estiver no chão { if (canDoubleJump)//Se puder pular uma segunda vez { if (!doubleJumping) //Se ainda não pulou o segundo pulo { if (UNInput.GetButtonDown(i, ButtonCode.A) || (Input.GetKeyDown(KeyCode.KeypadEnter) && usingKeyboard)) //Se o jogador apertar o botão de pulo { Jump(); //Função de pulo doubleJumping = true; //pulou segundo pulo } } } } gravity += Vector3.down * forceGravity * Time.deltaTime; //Adicionando a gravidade controller.Move(((transform.rotation * Vector3.forward * currentSpeed) * movement.magnitude * Time.deltaTime) + (gravity * Time.deltaTime)); //Movimentando } else { controller.Move(gravity * Time.deltaTime); //Somente Adicionar a gravidade } if (gravity.y < -forceGravity) //Se a gravidade for maior que a força gravitacional { gravity = Vector3.down * forceGravity; //Setando o valor máximo da gravidade } }