public float rightStick(int player_num, string x_or_y) { XboxController player; if (player_num == 1) { player = player01; } else if (player_num == 2) { player = player02; } else { return(0f); } XboxAxis axis; if (x_or_y == "X") { axis = XboxAxis.RightStickX; } else if (x_or_y == "Y") { axis = XboxAxis.RightStickY; } else { return(0f); } return(XCI.GetAxisRaw(axis, player)); }
public virtual void Update(XboxController controller) { // movement Vector3 moveDirection = new Vector3(XCI.GetAxisRaw(XboxAxis.LeftStickX, controller), 0, XCI.GetAxisRaw(XboxAxis.LeftStickY, controller)); _characterController.Move(moveDirection); // throw if (XCI.GetButton(XboxButton.RightBumper, controller) && _straightCoolDownTimer <= 0 && Time.time >= _straightThrowAvailableTime) { _straightCoolDownTimer = _settings.StraightCoolDown; _tossAvailableTime = Time.time + _settings.ThrowDeadzoneDuration; _characterController.Throw(); } if (_settings.StraightCoolDown > 0) { _straightCoolDownTimer -= Time.deltaTime; } // toss if (XCI.GetButton(XboxButton.LeftBumper, controller) && _arcCoolDownTimer <= 0 && Time.time >= _tossAvailableTime) { _arcCoolDownTimer = _settings.ArcCoolDown; _straightThrowAvailableTime = Time.time + _settings.ThrowDeadzoneDuration; _characterController.Toss(); } if (_settings.ArcCoolDown > 0) { _arcCoolDownTimer -= Time.deltaTime; } }
public void SettingChange() { if (canUseAxis) { if ((XCI.GetAxisRaw(XboxAxis.LeftStickX, XboxController.First) == 1 || KCI.GetAxisRaw(KeyboardAxis.Horizontal, KeyboardController.First) == 1) && numberRound < maxValue) { canUseAxis = false; numberRound++; GameObject.Find("AudioHandler").GetComponent <AudioBehaviour> ().audios [5].Play(); SettingText(); } if ((XCI.GetAxisRaw(XboxAxis.LeftStickX, XboxController.All) == -1 || KCI.GetAxisRaw(KeyboardAxis.Horizontal, KeyboardController.First) == -1) && numberRound > minValue) { canUseAxis = false; numberRound--; GameObject.Find("AudioHandler").GetComponent <AudioBehaviour> ().audios [5].Play(); SettingText(); } } if (XCI.GetAxisRaw(XboxAxis.LeftStickX, XboxController.First) == 0 && KCI.GetAxisRaw(KeyboardAxis.Horizontal, KeyboardController.First) == 0) { canUseAxis = true; } }
// Update is called once per frame void Update() { if (!GetComponent <Player>().IsDead() && m_gameManager.m_inputOn) { Vector2 rightInput = new Vector2(XCI.GetAxisRaw(XboxAxis.RightStickX, controller), XCI.GetAxisRaw(XboxAxis.RightStickY, controller)); if (rightInput.x != 0 || rightInput.y != 0) { m_aim.x = rightInput.x; m_aim.y = rightInput.y; m_aim.z = 0; m_aim.Normalize(); Vector3 up = new Vector3(0, 0.9f); Debug.DrawRay(this.transform.position + up, m_aim); m_timeBetweenShots += Time.deltaTime; if (GetComponent <ColourController>().m_firstBulletSlot&& m_timeBetweenShots >= m_fireRate) { CreateBullet(m_bullet1, m_aim + transform.position + up); } if (!GetComponent <ColourController>().m_firstBulletSlot&& m_timeBetweenShots >= m_fireRate) { CreateBullet(m_bullet2, m_aim + transform.position + up); } } } }
//------------------------------------------------------------------------------------------ // Use this for initialization, called when the script is first accessed. //------------------------------------------------------------------------------------------ void Start() { //m_goPlayerReticleCopy = Instantiate(m_goPlayerReticle, new Vector3(10.0f, 1.01f, -7.0f), Quaternion.Euler(90.0f, 0.0f, 0.0f)); //m_goPlayerReticleCopy.GetComponent<PlayerRetical>().m_player = gameObject; //m_scpPlayerReticle = m_goPlayerReticleCopy.GetComponent<PlayerRetical>(); //m_goPlayerReticleCopy.SetActive(false); //Xbox Stick Axis' m_axisX = XCI.GetAxisRaw(XboxAxis.LeftStickX, controller); m_axisY = XCI.GetAxisRaw(XboxAxis.LeftStickY, controller); // Getting the rigidBody of the players so we can move them. m_rb = GetComponent <Rigidbody>(); // S.etting current speed to original speed m_fCurrentSpeed = m_fSpeed; m_nCurrentHealth = m_nSpawnHealth; //SetHealthText(); m_Animator = transform.GetChild(0).GetComponent <Animator>(); m_psDizzy.Stop(); }
void FixedUpdate() { Vector3 moveForward = this.transform.rotation * Vector3.forward; Vector3 moveBack = this.transform.rotation * Vector3.back; float turn = rotSpeed * Time.deltaTime; Quaternion rotationPos = Quaternion.Euler(0, turn, 0); Quaternion rotationNeg = Quaternion.Euler(0, -turn, 0); //movement.x = XCI.GetAxisRaw(XboxAxis.LeftStickX, XboxController.All); //movement.z = XCI.GetAxisRaw(XboxAxis.LeftStickY, controller); //if (movement.x > 0) //{ // rigidbody.velocity += Vector3.right * velocity * Time.deltaTime * 10; //} //if (movement.x < 0) //{ // rigidbody.velocity += Vector3.left * velocity * Time.deltaTime * 10; //} if (rightTiggerDown() == true) { velocity = 5; GetComponent <Rigidbody>().velocity += moveForward * velocity * Time.deltaTime * 10; } else { velocity = 0; } if (leftTiggerDown() == true) { velocity = 5; GetComponent <Rigidbody>().velocity += moveBack * velocity * Time.deltaTime * 10; } else { velocity = 0; } if (XCI.GetAxisRaw(XboxAxis.RightStickX, controller) > 0) { rigidbodys.MoveRotation(rigidbodys.rotation * rotationPos); } if (XCI.GetAxisRaw(XboxAxis.RightStickX, controller) < 0) { rigidbodys.MoveRotation(rigidbodys.rotation * rotationNeg); } if (GetComponent <Rigidbody>().velocity.magnitude > maxSpeed) { rigidbodys.velocity = rigidbodys.velocity.normalized * maxSpeed; } }
//private float prevTargetTheta = 0; // Update is called once per frame void Update() { if (follow_player) { target = GM.Instance.player; } keyboard(); joy += new Vector2(XCI.GetAxisRaw(XboxAxis.LeftStickX, ctlr), XCI.GetAxisRaw(XboxAxis.LeftStickY, ctlr)); if (target != null) { joy = target.transform.position - transform.position; } if (joy.x != 0 || joy.y != 0) { if (joy.y == 0) { targetTheta = 180 * joy.x * -1; } targetTheta = joy.x == 0 ? 90 * joy.y : (360 / (2 * Mathf.PI)) * Mathf.Atan(joy.y / joy.x); if (joy.x < 0) { targetTheta += 180; } if (targetTheta < 0) { targetTheta += 360; } if (joy.x > 0) { if ((transform.eulerAngles.z > 270 || transform.eulerAngles.z == 0) && joy.y > 0) { targetTheta += 360; } else if (transform.eulerAngles.z < 180 && joy.y < 0) { targetTheta -= 360; } } //deltaTheta = (targetTheta - transform.eulerAngles.z) % 360; deltaTheta = Mathf.LerpAngle(transform.eulerAngles.z, targetTheta, Time.deltaTime * turnRadius); } transform.Rotate(Vector3.forward * deltaTheta - transform.eulerAngles); //Mathf.Clamp(deltaTheta,-1 * turnRadius,turnRadius)); //prevTargetTheta = targetTheta; }
void ApplyTriggerThrust() { float rightThrust = XCI.GetAxisRaw(XboxAxis.RightTrigger, xboxController); float leftThrust = XCI.GetAxisRaw(XboxAxis.LeftTrigger, xboxController); Vector3 thrust = (transform.up * rightThrust * maxThrust) + (-transform.up * leftThrust * maxThrust); rb2d.AddForce(thrust, ForceMode2D.Force); }
// Update is called once per frame void FixedUpdate() { //Tijdelijk //if (Input.GetKey(KeyCode.W)) //{ // transform.position += new Vector3(-_Speed * Time.fixedDeltaTime, 0, 0); //} //if (Input.GetKey(KeyCode.S)) //{ // transform.position += new Vector3(_Speed * Time.fixedDeltaTime, 0, 0); //} //if (Input.GetKey(KeyCode.D)) //{ // transform.position += new Vector3(0, 0, _Speed * Time.fixedDeltaTime); //} //if (Input.GetKey(KeyCode.A)) //{ // transform.position += new Vector3(0, 0, -_Speed * Time.fixedDeltaTime); //} //if (Input.GetKeyDown(KeyCode.Space)) //{ // _RigidBody.AddForce(Vector3.up * _JumpHight, ForceMode.Impulse); //} transform.position += new Vector3(XCI.GetAxisRaw(XboxAxis.LeftStickX, Player) * _CurrantSpeed * Time.fixedDeltaTime, 0, XCI.GetAxisRaw(XboxAxis.LeftStickY, Player) * _CurrantSpeed * Time.fixedDeltaTime); //if (XCI.GetAxisRaw(XboxAxis.RightStickX, Player) != 0 && XCI.GetAxisRaw(XboxAxis.RightStickY, Player) != 0) //{ // float horizontal = XCI.GetAxisRaw(XboxAxis.RightStickX, Player) * Time.fixedDeltaTime; // float vertical = XCI.GetAxisRaw(XboxAxis.RightStickY, Player) * Time.fixedDeltaTime; // float angle = Mathf.Atan2(vertical, horizontal) * Mathf.Rad2Deg; // gameObject.transform.eulerAngles = new Vector3(0, -angle, 0); //} transform.LookAt(transform.position + new Vector3(XCI.GetAxisRaw(XboxAxis.RightStickX, Player), 0.0f, XCI.GetAxisRaw(XboxAxis.RightStickY, Player)), -Vector3.forward); transform.rotation = new Quaternion(0, transform.rotation.y, 0, transform.rotation.w); if (XCI.GetButtonDown(XboxButton.A, Player) && _IsOnGround) { _RigidBody.AddForce(Vector3.up * _JumpHight, ForceMode.Impulse); } if (Physics.Raycast(transform.position, Vector3.down, 0.6f, _Mask)) { _IsOnGround = true; } else { _IsOnGround = false; } //if (!_IsOnGround) //{ // _CurrantSpeed = _Speed / 4; //} //else { _CurrantSpeed = _Speed; } }
void setPosition() { float keyboard = Input.GetAxisRaw("SliderV"); float Xbox = XCI.GetAxisRaw(XboxAxis.LeftStickY); if (keyboard == 1 || Xbox == 1) { Setting("sound"); } }
// Update is called once per frame void FixedUpdate() { Vector3 normal = _Physics._CombinedSurviceNormal; float triggers = 0; triggers += XCI.GetAxisRaw(XboxAxis.RightTrigger); triggers -= XCI.GetAxisRaw(XboxAxis.LeftTrigger); transform.rotation = Quaternion.Lerp(transform.rotation, Quaternion.FromToRotation(transform.up, (normal)) * transform.rotation, 5 * Time.deltaTime); //transform.Rotate(Vector3.forward * -triggers * 100f * Time.deltaTime, Space.Self); }
void Walk() { if (isKeyboard) { input = new Vector2(KCI.GetAxisRaw(KeyboardAxis.Horizontal, Kcontroller), KCI.GetAxisRaw(KeyboardAxis.Vertical, Kcontroller)); } else { input = new Vector2(XCI.GetAxisRaw(XboxAxis.LeftStickX, Xcontroller), XCI.GetAxisRaw(XboxAxis.LeftStickY, Xcontroller)); } }
public bool leftTiggerDown() { if (XCI.GetAxisRaw(XboxAxis.LeftTrigger, controller) != 0) { return(true); } else { return(false); } }
void setValue() { float keyboard = Input.GetAxisRaw("SliderH") * 0.01f; float Xbox = XCI.GetAxisRaw(XboxAxis.LeftStickX) * 0.01f; if (setSlider == "sound") { soundSlider.GetComponent <Slider>().value += (keyboard + Xbox); AudioListener.volume = soundSlider.GetComponent <Slider>().value; PlayerPrefs.SetFloat("SoundValue", soundSlider.GetComponent <Slider>().value); } }
/// <summary> /// returns a specified axis /// </summary> /// <param name="axis">One of the analogue sticks, or the dpad</param> /// <param name="controlIndex">The controller number</param> /// <param name="raw">if raw is false then the controlIndex will be returned with a deadspot</param> /// <returns></returns> public static Vector2 GetAxis(Axis axis, Index controlIndex, bool raw = false) { XboxAxisz xName = XboxAxisz.LeftStickX; XboxAxisz yName = XboxAxisz.LeftStickY; Vector2 axisXY = Vector3.zero; switch (axis) { case Axis.Dpad: axisXY.x = XCI.GetDPad(XboxDPad.Up)? 1.0f:0.0f; axisXY.x -= XCI.GetDPad(XboxDPad.Down) ? 1.0f : 0.0f; axisXY.y = XCI.GetDPad(XboxDPad.Right) ? 1.0f : 0.0f; axisXY.y -= XCI.GetDPad(XboxDPad.Left) ? 1.0f : 0.0f; return(axisXY); //break; case Axis.LeftStick: xName = XboxAxisz.LeftStickX; // "XboxAxisXJoy" + (int)controlIndex; yName = XboxAxisz.LeftStickY; //"XboxAxisYJoy" + (int)controlIndex; break; case Axis.RightStick: xName = XboxAxisz.RightStickX; //"XboxAxis4Joy" + (int)controlIndex; yName = XboxAxisz.RightStickY; //"XboxAxis5Joy" + (int)controlIndex; break; } ; try { if (raw == false) { axisXY.x = XCI.GetAxis((XboxAxis)xName, (XboxController)controlIndex); axisXY.y = XCI.GetAxis((XboxAxis)yName, (XboxController)controlIndex); } else { axisXY.x = XCI.GetAxisRaw((XboxAxis)xName, (XboxController)controlIndex); axisXY.y = XCI.GetAxisRaw((XboxAxis)yName, (XboxController)controlIndex); } } catch (System.Exception e) { Debug.LogError(e); Debug.LogWarning("Have you set up all axes correctly? \nThe easiest solution is to replace the InputManager.asset with version located in the GamepadInput package. \nWarning: do so will overwrite any existing input"); } return(axisXY); }
//-------------------------------------------------------------------------------- // Function allows for the Striker to move //-------------------------------------------------------------------------------- private void Move() { // Both floats get direction of the Xbox controller's left stick float axisX = XCI.GetAxisRaw(XboxAxis.LeftStickX, Controller); float axisZ = XCI.GetAxisRaw(XboxAxis.LeftStickY, Controller); // Creates a "new" Vector3 to allow movement Vector3 movement = new Vector3(axisX, 0, axisZ) * movementSpeed; // Applies movement physics to the player's Rigidbody rigidBody.MovePosition(rigidBody.position + movement * Time.deltaTime); // Sets the Striker's velocity to be zero rigidBody.velocity = Vector3.zero; // Sets axisX to equal previous Rotation's X value if axisX is zero if (axisX == 0f) { axisX = prevRotateX; } // Otherwise the previous Rotation X records the axisX else { prevRotateX = axisX; } // Sets axisZ to equal previous Rotation's Z value if axisZ is zero if (axisZ == 0f) { axisZ = prevRotateZ; } // Otherwise the previous Rotation Z records the axisZ else { prevRotateZ = axisZ; } // Runs code in braces if the left control stick is not in the centre if (axisX != 0 || axisZ != 0) { // Creates a "new" direction Vector3 of the left control sticks direction Vector3 directionVector = new Vector3(axisX, 0, axisZ); // Makes the player look in direction of the directionVector transform.rotation = Quaternion.LookRotation(directionVector); } // Angular velocity of player is set to be a zero Vector rigidBody.angularVelocity = Vector3.zero; }
void HandleAiming() { float x = XCI.GetAxisRaw(XboxAxis.RightStickX, xboxController); float y = XCI.GetAxisRaw(XboxAxis.RightStickY, xboxController); rInput = new Vector2(x, y); if (rInput.magnitude > 0) { // Original Rotation Setup var angle = Mathf.Atan2(rInput.y, rInput.x) * Mathf.Rad2Deg - 90; //angle *= (2 / 3); retical.eulerAngles = new Vector3(0, 0, angle); float adjustedAngle; float max = 0.0f; float min = 0.0f; if (retical.localEulerAngles.z > 180) { //smoothing float angleOffset = 360 - retical.localEulerAngles.z; adjustedAngle = 360 - (angleOffset * 0.85f); max = reticalHighMax; min = reticalHighMin; } else { //smoothing adjustedAngle = retical.localEulerAngles.z; // * (2 / 3); adjustedAngle *= 0.85f; max = reticalLowMax; min = reticalLowMin; } Vector3 angles = new Vector3(0, 0, adjustedAngle); //if (playerInfo.playerNum == 1) { Debug.Log("Input: " + rInput + " Aim angle: " + adjustedAngle + " Local: " + retical.localEulerAngles.z); } retical.localEulerAngles = angles; if (retical.localEulerAngles.z > max || retical.localEulerAngles.z < min) { retical.localEulerAngles = new Vector3(0, 0, Mathf.Clamp(retical.localEulerAngles.z, min, max)); } } }
public override void Update(XboxController controller) { // aim Vector3 aimDirection = Vector3.zero; if (XCI.GetAxisRaw(XboxAxis.RightStickX, controller) != 0 || XCI.GetAxisRaw(XboxAxis.RightStickY, controller) != 0) { aimDirection = new Vector3(XCI.GetAxisRaw(XboxAxis.RightStickX, controller), 0, XCI.GetAxisRaw(XboxAxis.RightStickY, controller)); } _characterController.Aim(aimDirection.normalized); base.Update(controller); }
//------------------------------------------------------------ // Function allows for the Striker to rotate //------------------------------------------------------------ private void Rotate() { // Only runs if the striker is not performing their special if (!strikerDoingSpecial) { // Both floats get direction of the Xbox controller's right stick float rotateAxisX = XCI.GetAxisRaw(XboxAxis.RightStickX, Controller); float rotateAxisZ = XCI.GetAxisRaw(XboxAxis.RightStickY, Controller); // Checks if the right stick is at default position on the x axis if (rotateAxisX == 0f) { // If so, set the rotation x to be the previous frame's rotation x rotateAxisX = prevRotateX; } // Otherwise store current rotate x into the previous frame rotate x else { prevRotateX = rotateAxisX; } // Checks if the right stick is at default position on the y axis if (rotateAxisZ == 0f) { // If so, set the rotation z to be the previous frame's rotation z rotateAxisZ = prevRotateZ; } // Otherwise store current rotate z into the previous frame rotate z else { prevRotateZ = rotateAxisZ; } // Checks if either rotate x isn't zero or rotate z isn't zero if (rotateAxisX != 0 || rotateAxisZ != 0) { // If one variable isn't zero, create a "new" Vector3 refering to looking direction Vector3 directionVector = new Vector3(rotateAxisX, 0, rotateAxisZ); // Allows for the striker to look in same direction as right stick's position transform.rotation = Quaternion.LookRotation(directionVector); } // Sets the angular velocity of the Striker to be zero rigidBody.angularVelocity = Vector3.zero; } }
/* * Override of the base GetAxisRaw to use xInput */ public override float GetAxisRaw(string axisName) { if (axisName == "Horizontal") { return(XCI.GetAxisRaw(XboxAxis.LeftStickX, m_controller)); } else if (axisName == "Vertical") { return(XCI.GetAxisRaw(XboxAxis.LeftStickY, m_controller)); } else { return(0); } }
// Update is called once per frame void Update() { if (m_playerNumber != -1) { XboxController controller = XboxController.All; XboxAxis stick = XboxAxis.LeftStickX; XboxButton activate = XboxButton.LeftBumper; switch (m_playerNumber) { case 1: controller = XboxController.First; stick = XboxAxis.LeftStickX; activate = XboxButton.LeftBumper; break; case 2: controller = XboxController.First; stick = XboxAxis.RightStickX; activate = XboxButton.RightBumper; break; case 3: controller = XboxController.Second; stick = XboxAxis.LeftStickX; activate = XboxButton.LeftBumper; break; case 4: controller = XboxController.Second; stick = XboxAxis.RightStickX; activate = XboxButton.RightBumper; break; } m_rotationVelocity += XCI.GetAxisRaw(stick, controller) * m_rotationSpeed * Time.deltaTime; Quaternion rotation = Quaternion.Euler(0, m_rotationVelocity, 0); transform.rotation *= rotation; m_rotationVelocity -= m_rotationDrag * m_rotationVelocity * Time.deltaTime; if (XCI.GetButton(activate, controller)) { m_rigidbody.AddForce(transform.forward * m_speed); } } }
void FixedUpdate() { float turn = rotSpeed * Time.deltaTime; Quaternion rotationPos = Quaternion.Euler(0, turn, 0); Quaternion rotationNeg = Quaternion.Euler(0, -turn, 0); if (XCI.GetAxisRaw(XboxAxis.RightStickX, controller) > 0) { rigidbodys.MoveRotation(rigidbodys.rotation * rotationPos); } if (XCI.GetAxisRaw(XboxAxis.RightStickX, controller) < 0) { rigidbodys.MoveRotation(rigidbodys.rotation * rotationNeg); } }
// Update is called once per frame void Update() { joy = new Vector2(0, 0); #if UNITY_EDITOR keyboard(); #endif joy += new Vector2(XCI.GetAxisRaw(XboxAxis.LeftStickX, ctlr), XCI.GetAxisRaw(XboxAxis.LeftStickY, ctlr)); //only apply to player if (PHP && (XCI.GetButton(XboxButton.A, ctlr) #if UNITY_EDITOR || Input.GetKey(KeyCode.LeftShift) #endif ) && !cooldown) { _gear = gear.boost; } else { _gear = gear.normal; } if (dash_enabled && PHP && (XCI.GetButton(XboxButton.X, ctlr) #if UNITY_EDITOR || Input.GetKeyDown(KeyCode.F) #endif ) && !PlayerHP.invuln && dash_off_cooldown) { StartCoroutine(dash(dash_length, dash_width)); } if (!stunned && (!turtle_script.currently_active || turtle_script.move)) { move(); } dash_timer = Mathf.Clamp(dash_timer - Time.deltaTime, -1, dash_timer); if (dash_timer < 0) { dash_off_cooldown = true; } CameraUtil.keepInCamBounds(transform.root); }
void verifyWalk() { if (Input.GetKeyDown(KeyCode.A) || XCI.GetAxisRaw(XboxAxis.LeftStickX, Xcontroller) == -1f) { left = true; } if (Input.GetKeyDown(KeyCode.D) || XCI.GetAxisRaw(XboxAxis.LeftStickX, Xcontroller) == 1f) { right = true; } if (left && right) { StartCoroutine(passInstruction(1)); } }
private void FixedUpdate() { //Left Stick input inputDirection = new Vector3(XCI.GetAxisRaw(XboxAxis.LeftStickX, controller), 0, XCI.GetAxisRaw(XboxAxis.LeftStickY, controller)); if (inputDirection != Vector3.zero) { //Vector between the end from the start. targetDestination from the current position vecBetween = inputDirection; //Get the rotation from the vecBetween the above two points targetRotation = Quaternion.LookRotation(vecBetween); //Lerp the rotation from its current rotation to its new rotation rigidBody.rotation = Quaternion.Slerp(rigidBody.rotation, targetRotation, movementSpeed * Time.fixedDeltaTime); } //Velocity of the player. Vector3 velocity = inputDirection * movementSpeed * Time.fixedDeltaTime; //playerAnimator.speed = velocity.magnitude * 8.0f; // playerAnimator.SetFloat("Speed", velocity.magnitude); //Moves the player towards the inputDirection, multiplied by the speed and smoothed with Time.fixedDeltaTime. rigidBody.MovePosition(rigidBody.position + velocity); //Debug.Log("Velocity: " + velocity * 1.0f); //While the debug sphere is attached to the player. if (inputDebugSphere != null) { //Displays the current input from the contoller inputDebugSphere.transform.position = rigidBody.position + inputDirection * 1.5f; } //Remove velocity and angularVelocity rigidBody.velocity = Vector3.zero; rigidBody.angularVelocity = Vector3.zero; }
void Move() { y = XCI.GetAxisRaw(XboxAxis.LeftStickY, controller); x = XCI.GetAxisRaw(XboxAxis.LeftStickX, controller); movement = new Vector3(x, 0, y); if (x != 0 || y != 0) { rb.velocity = transform.forward * speed; } else { rb.velocity = Vector3.zero; } if (x == 0f) { x = prevRotatex; } else { prevRotatex = x; } if (y == 0f) { y = prevRotatey; } else { prevRotatey = y; } if (x != 0 || y != 0) { Vector3 direction = new Vector3(x, 0, y); transform.rotation = Quaternion.LookRotation(direction); } }
void Update() { if (XCI.GetButtonDown(XboxButton.A, XboxController.First)) { _current.Value.onClick.Invoke(); } if (XCI.GetButtonDown(XboxButton.B, XboxController.First)) { _onBackButton.Invoke(); UpdateSelectedButton(); } // DPad. if (XCI.GetButtonDown(XboxButton.DPadRight, XboxController.First)) { Next(); } if (XCI.GetButtonDown(XboxButton.DPadLeft, XboxController.First)) { Previous(); } // Joystick. if (XCI.GetAxisRaw(XboxAxis.LeftStickX, XboxController.First) > 0f) { if (Time.unscaledTime >= _nextTime) { Next(); _nextTime = Time.unscaledTime + _interval; } } if (XCI.GetAxisRaw(XboxAxis.LeftStickX, XboxController.First) < 0f) { if (Time.unscaledTime >= _nextTime) { Previous(); _nextTime = Time.unscaledTime + _interval; } } }
void GetPlayerInput() { if (XCI.GetAxisRaw(XboxAxis.LeftStickY) > 0) { if (menuOption != 2) { menuOption++; } } else if (XCI.GetAxisRaw(XboxAxis.LeftStickY) < 0) { if (menuOption != 0) { menuOption--; } } moveLocation = menuOptions [menuOption].transform.position; GetAButton(); }
// Rotation of player public void Turning() { // checks if the controller is being used if (xboxController.useController) { float rotateAxisX = XCI.GetAxisRaw(XboxAxis.RightStickX, xboxController.controller); float rotateAxisZ = XCI.GetAxisRaw(XboxAxis.RightStickY, xboxController.controller); // puts the rotation x and z axis in a new vector directionVector = new Vector3(rotateAxisX, 0, rotateAxisZ); if (directionVector.magnitude < 0.1f) { directionVector = prevRotDirection; } directionVector = directionVector.normalized; prevRotDirection = directionVector; transform.localRotation = Quaternion.LookRotation(directionVector); } }
void ControllerUpdate() { //add movment to the player if the user adds input //cc.Move(transform.right * controller.LeftStick.X * speed * Time.deltaTime); //cc.Move(transform.forward * controller.LeftStick.Y * speed * Time.deltaTime); cc.Move((((transform.right * XCI.GetAxis(XboxAxis.LeftStickX, controller)) + (transform.forward * XCI.GetAxis(XboxAxis.LeftStickY, controller)).normalized) * speed * Time.deltaTime)); controllerRetical.transform.position = transform.position + new Vector3(XCI.GetAxisRaw(XboxAxis.RightStickX, controller), 0, XCI.GetAxisRaw(XboxAxis.RightStickY, controller)); //shooting on controller if (XCI.GetAxis(XboxAxis.RightTrigger, controller) > 0 && ShootTimer > BufferTime) { ShootTimer = 0.0f; foreach (GameObject i in slimes) { i.GetComponent <SlimeActions>().Shoot(lastRot, mass); } } }