void Update() { input = MappedInput.InputDevices[_controllerId]; Vector3 leftStick = input.GetAxis2DCircleClamp(MappedAxis.Horizontal, MappedAxis.Vertical); var fixedLeftStick = Camera.main.transform.rotation * new Vector3(leftStick.x, 0, leftStick.y); fixedLeftStick = new Vector3(fixedLeftStick.x, 0, fixedLeftStick.z); if (fixedLeftStick.magnitude > 0) { animator.SetBool("Running", true); Move(fixedLeftStick * Time.deltaTime); } else { animator.SetBool("Running", false); } Vector3 rightStick = input.GetAxis2DCircleClamp(MappedAxis.AimX, MappedAxis.AimY); var aimDir = new Vector3(rightStick.x, 0, rightStick.y).normalized; var fixedAimDir = Camera.main.transform.rotation * aimDir; fixedAimDir = new Vector3(fixedAimDir.x, 0, fixedAimDir.z); if (rightStick.magnitude != 0) { transform.rotation = Quaternion.LookRotation(fixedAimDir.normalized); } else { fixedAimDir = transform.forward; } _aimingReticle.transform.position = transform.position + fixedAimDir; if (input.GetAxis(MappedAxis.ShootGravGun) != 0 && fixedAimDir.magnitude > 0 && ShootingCooldownCoroutine == null) { ShootingCooldownCoroutine = StartCoroutine(ShootOnCooldown()); animator.SetBool("Shooting", true); } else if (input.GetAxis(MappedAxis.ShootGravGun) == 0) { animator.SetBool("Shooting", false); } if (input.GetAxis(MappedAxis.ChangeCameraAngle) != 0) { float changeCameraDir = input.GetAxis(MappedAxis.ChangeCameraAngle); CameraController.Instance.Rotate(-changeCameraDir); } }
private void UpdateInput() { inputPreviousToggleWalkieOn = inputToggleWalkieOn; Vector2 keyboardMoveMult = new Vector2(1, 1); Vector2 xboxMoveMult = new Vector2(1, -1); // xbox gives the y-axis for movement negated Vector2 finalMoveMult = xboxMoveMult; Vector2 keyboardLookMult = new Vector2(1, -1); // keyboard gives the y-axis for looking negated Vector2 xboxLookMult = new Vector2(1, 1); Vector2 finalLookMult = xboxLookMult; finalInputBindings = xboxInputBindings; if (inputDevice.Type == InputDevice.InputDeviceType.KEYBOARD) { finalMoveMult = keyboardMoveMult; finalLookMult = keyboardLookMult; finalInputBindings = keyboardInputBindings; } inputMove = new Vector2(inputDevice.GetAxis(finalInputBindings["inputMoveX"]) * finalMoveMult.x, inputDevice.GetAxis(finalInputBindings["inputMoveY"]) * finalMoveMult.y); inputLook = new Vector2(inputDevice.GetAxis(finalInputBindings["inputLookX"]) * finalLookMult.x, inputDevice.GetAxis(finalInputBindings["inputLookY"]) * finalLookMult.y); inputJump = inputDevice.GetAxis(finalInputBindings["inputJump"]); inputToggleWalkieOn = inputDevice.GetAxis(finalInputBindings["inputToggleWalkieOn"]); inputAntennaIn = inputDevice.GetAxis(finalInputBindings["inputAntennaIn"]); inputAntennaOut = inputDevice.GetAxis(finalInputBindings["inputAntennaOut"]); }
private void Gamepad() { float rightSitckX = InputDevice.GetAxisRaw(MappedAxis.AimX); float rightSitckY = InputDevice.GetAxisRaw(MappedAxis.AimY); Vector2 aimDir = new Vector2(rightSitckX, rightSitckY); if (aimDir == Vector2.zero) { aimDir = _lastAimDir; } else { _lastAimDir = aimDir; } AimReticle(aimDir); if (InputDevice.GetIsAxisTappedPos(MappedAxis.ChangeGravAxis, .5f)) { ChangeGravityTowardsDir(Vector2.up); } if (InputDevice.GetIsAxisTappedNeg(MappedAxis.ChangeGravAxis, -.5f)) { ChangeGravityTowardsDir(Vector2.down); } if (InputDevice.GetIsAxisTappedPos(MappedAxis.ChangeGrav) && InputDevice.GetAxis(MappedAxis.ChangeGrav) > 0) { FlipGravity(); } if (InputDevice.GetIsAxisTappedPos(MappedAxis.ShootGravGun) && aimDir.magnitude > 0) { ShootGravityGun(aimDir, ProjectileControllerType.Normal); } if (InputDevice.GetButtonDown(MappedButton.Special)) { DoSpecial(aimDir); } }
void FixedUpdate() { float verticalAxis = attachedDevice.GetAxis(MappedAxis.MoveVertical); float horizontalLeftAxis = attachedDevice.GetAxis(MappedAxis.MoveHorizontal); float horizontalAxis = horizontalLeftAxis; //float horizontalAxis = attachedDevice.GetAxis (MappedAxis.LookHorizontal); //float verticalRightAxis = attachedDevice.GetAxis (MappedAxis.LookVertical); if (playerRBody == null) { return; } if (playerRBody.velocity.sqrMagnitude <= float.Epsilon) { isCharging = false; } if (playerRBody.velocity.y < -1.0f && playerBelow == null) {//bounce issue isGrounded = false; seperateFromPlayerBelow(); } if (isCharging) { return; } // MOVEMENT if (isGrounded) { Quaternion a = Quaternion.LookRotation(transform.forward, transform.up); if (horizontalAxis != 0.0f || verticalAxis != 0.0f) { Vector3 targetV = (new Vector3(horizontalLeftAxis, 0.0f, verticalAxis)).normalized; Quaternion b = Quaternion.LookRotation(targetV, transform.up); Quaternion rot = Quaternion.Lerp(a, b, Time.fixedDeltaTime * rotateSpeed); playerRBody.MoveRotation(rot); if (playerAbove != null) { playerAbove.SendMessage("OnPlayerBelowRotate", rot * Quaternion.Inverse(a), SendMessageOptions.DontRequireReceiver); } if (Vector3.Dot(targetV, transform.forward) > 0.95f && playerRBody.velocity.magnitude < maxVelocity) { seperateFromPlayerBelow(); Vector3 movingForce = movementSpeed * transform.forward * Time.fixedDeltaTime * 100.0f; playerRBody.AddForce(movingForce, ForceMode.Force); } } /* * float pressedAngle = getAngle(verticalAxis, horizontalLeftAxis); * * if (pressedAngle >= 1.0f || pressedAngle <= 0.0f) * { * float pressedOpposite = pressedAngle + 180; * float currentOpposite = currentAngle + 180; * if (pressedOpposite >= 360) * { * pressedOpposite -= 360; * } * if (currentOpposite >= 360) * { * currentOpposite -= 360; * } * if (Mathf.Abs(currentAngle - pressedAngle) > 5.0f) * { * * bool isPressedOpposite = false; * bool isCurrentOpposite = false; * * // check if pressedAngle is between 0 - 180 * if (pressedAngle >= 180 && pressedAngle < 360) * { * isPressedOpposite = true; * } * // check if current is between 0 - 180 * if (currentAngle >= 180 && currentAngle < 360) * { * isCurrentOpposite = true; * } * * if (isPressedOpposite && isCurrentOpposite) * { * if (currentOpposite >= pressedOpposite) * { * // turn cw * turnClockWise(); * } * else * { * // turn acw * turnAntiClockWise(); * } * } * else if (isPressedOpposite && !isCurrentOpposite) * { * if (currentAngle >= pressedOpposite) * { * // turn acw * turnAntiClockWise(); * } * else * { * // turn cw * turnClockWise(); * } * } * else if (!isPressedOpposite && isCurrentOpposite) * { * if (currentOpposite >= pressedAngle) * { * // turn acw * turnAntiClockWise(); * } * else * { * // turn cw * turnClockWise(); * } * } * else if (!isPressedOpposite && !isCurrentOpposite) * { * if (currentAngle >= pressedAngle) * { * // turn cw * turnClockWise(); * * } * else * { * // turn acw * turnAntiClockWise(); * } * } * } * else * { * // stop rotation * //stopRotation(); * } * if (playerRBody.velocity.magnitude < maxVelocity) * { * Vector3 movingForce = movementSpeed * transform.forward * Time.fixedDeltaTime * 100; * playerRBody.AddForce(movingForce, ForceMode.Force); * } * } * else * { * // stop rotation * //stopRotation(); * }*/ /*if (pressedAngle > currentAngle && pressedAngle < currentOpposite) { * if (Mathf.Abs (currentAngle - pressedAngle) > 5.0f) { * // acw * Quaternion newRotation = Quaternion.Euler (transform.up * -3.0f); * playerRBody.MoveRotation (playerRBody.rotation * newRotation); * } * } else { * if (Mathf.Abs (currentAngle - pressedAngle) > 5.0f) { * //cw * Quaternion newRotation = Quaternion.Euler (transform.up * 3.0f); * playerRBody.MoveRotation (playerRBody.rotation * newRotation); * } * }*/ /*if (verticalAxis != 0.0f && playerRBody.velocity.magnitude < maxVelocity) { * Vector3 movingForce = verticalAxis * movementSpeed * transform.forward * Time.fixedDeltaTime; * playerRBody.AddForce (movingForce, ForceMode.Impulse); * }*/ } float mag = playerRBody.velocity.magnitude; // Velocity Check if (mag < 0.01f || playerBelow == null) { animator.SetFloat("velocity", mag); } // ROTATION //Quaternion newRotation = Quaternion.Euler( transform.up * horizontalAxis * rotateSpeed); //playerRBody.MoveRotation (playerRBody.rotation * newRotation); // print ("drag " + playerRBody.drag); // print ("isBouncing " + isBouncing); // print ("isJumping " + isJumping); // print ("isGrounded " + isGrounded); }
public override void OnInspectorGUI() { base.OnInspectorGUI(); InputDevice device = (InputDevice)target; GUILayout.Label("Type: " + device.GetType().ToString()); GUILayout.Label("Mapped Axes", EditorStyles.boldLabel); for (int i = 0; i < InputDevice.allMappedAxisTypes.Count; i++) { GUILayout.Label(string.Format("{0} ({1}): {2}", InputDevice.allMappedAxisTypes[i], device.GetAxisName(InputDevice.allMappedAxisTypes[i]), device.GetAxis(InputDevice.allMappedAxisTypes[i]))); } GUILayout.Space(10); GUILayout.Label("Mapped Buttons", EditorStyles.boldLabel); for (int i = 0; i < InputDevice.allMappedButtonTypes.Count; i++) { GUILayout.Label(string.Format("{0} ({1}): {2}", InputDevice.allMappedButtonTypes[i], device.GetButtonName(InputDevice.allMappedButtonTypes[i]), device.GetButton(InputDevice.allMappedButtonTypes[i]))); } }