private float AxisCheck(string controlname, bool getRawValue = false) { Sinput.SinputUpdate(); float returnV = 0f; float v = 0f; for (int i = 0; i < joystickIndeces.Count; i++) { if (!getRawValue) { v = Sinput.GetAxis(controlname, (InputDeviceSlot)joystickIndeces[i]); } else { v = Sinput.GetAxisRaw(controlname, (InputDeviceSlot)joystickIndeces[i]); } if (Mathf.Abs(v) > Mathf.Abs(returnV)) { returnV = v; } } return(returnV); }
void move() { float horizontal, vertical; horizontal = Sinput.GetAxis("Horizontal", slot); vertical = Sinput.GetAxis("Vertical", slot); if (Mathf.Abs(horizontal) >= moveInputThreshhold || Mathf.Abs(vertical) >= moveInputThreshhold) { playerMovement.move(Sinput.GetAxis("Horizontal", slot), Sinput.GetAxis("Vertical", slot)); } }
void CheckInput() { for (int n = 0; n < buttons.Length; n++) { if (Sinput.GetButtonDown(buttons[n].name)) { buttons[n].SetState(true); buttons[n].events.Pressed?.Invoke(); } if (Sinput.GetButtonUp(buttons[n].name)) { buttons[n].SetState(false); buttons[n].events.Released?.Invoke(); } } for (int n = 0; n < axes.Length; n++) { bool state = false; for (int i = 0; i < axes[n].names.Length; i++) { float value = Sinput.GetAxis(axes[n].names[i]); state = Mathf.Abs(value) > 0f; if (axes[n].sendWhenZeroToo || state) { axes[n].AxisValue?.Invoke(value); break; } } bool prevState = axes[n].isPressed; axes[n].SetState(state); if (state) { if (!prevState) { axes[n].events.Pressed?.Invoke(); } } else if (prevState) { axes[n].events.Released?.Invoke(); } } for (int n = 0; n < joysticks.Length; n++) { bool state = false; for (int i = 0; i < joysticks[n].names.Length; i++) { Vector2 value = Sinput.GetVector(joysticks[n].names[i].x, joysticks[n].names[i].y, joysticks[n].normalizationMode != NormalizationMode.NotNormalize); state = value.sqrMagnitude > 0f; if (state && (joysticks[n].normalizationMode == NormalizationMode.NormalizeWithoutPithagoras)) { if (Mathf.Abs(value.x) > Mathf.Abs(value.y)) { value.x = Mathf.Sign(value.x); } else if (Mathf.Abs(value.x) < Mathf.Abs(value.y)) { value.y = Mathf.Sign(value.y); } else { value.x = Mathf.Sign(value.x); value.y = Mathf.Sign(value.y); } } if (joysticks[n].sendWhenZeroToo || state) { joysticks[n].JoystickValue?.Invoke(value); joysticks[n].JoystickMagnitude?.Invoke(value.magnitude); break; } } bool prevState = joysticks[n].isPressed; joysticks[n].SetState(state); if (state) { if (!prevState) { joysticks[n].events.Pressed?.Invoke(); } } else if (prevState) { joysticks[n].events.Released?.Invoke(); } } for (int n = 0; n < buttonStates.Length; n++) { bool state = true; foreach (SButtonState button in buttonStates[n].buttonsState) { if (Sinput.GetButton(button.name) != button.state) { state = false; break; } } bool prevState = buttonStates[n].isPressed; buttonStates[n].SetState(state); if (state) { if (!prevState) { buttonStates[n].events.Pressed?.Invoke(); } } else if (prevState) { buttonStates[n].events.Released?.Invoke(); } } }
public void Update() { if (Time.frameCount == lastUpdateFrame) { return; } lastUpdateFrame = Time.frameCount; for (int slot = 0; slot < rawValues.Length; slot++) { rawValues[slot] = Sinput.GetAxis(positiveControl, (InputDeviceSlot)slot) - Sinput.GetAxis(negativeControl, (InputDeviceSlot)slot); if (inversion[slot]) { rawValues[slot] *= -1f; } valuePrefersDeltaUse[slot] = true; if (!Sinput.PrefersDeltaUse(positiveControl, (InputDeviceSlot)slot) || !Sinput.PrefersDeltaUse(negativeControl, (InputDeviceSlot)slot)) { //the rawvalue this frame is from a framerate independent input like a mouse movement, so we don't want it smoothed and wanna force getAxis checks to return raw valuePrefersDeltaUse[slot] = false; } } for (int slot = 0; slot < controlValues.Length; slot++) { if (!valuePrefersDeltaUse[slot]) { //we're forcing things to be unsmoothed for now, zero smoothed input now so when we stop smoothing, it doesn't seem weird controlValues[slot] = 0f; } else { //shift to zero if (gravity > 0f) { if (rawValues[slot] == 0f || (rawValues[slot] < controlValues[slot] && controlValues[slot] > 0f) || (rawValues[slot] > controlValues[slot] && controlValues[slot] < 0f)) { if (controlValues[slot] > 0f) { controlValues[slot] -= gravity * Time.deltaTime; if (controlValues[slot] < 0f) { controlValues[slot] = 0f; } if (controlValues[slot] < rawValues[slot]) { controlValues[slot] = rawValues[slot]; } } else if (controlValues[slot] < 0f) { controlValues[slot] += gravity * Time.deltaTime; if (controlValues[slot] > 0f) { controlValues[slot] = 0f; } if (controlValues[slot] > rawValues[slot]) { controlValues[slot] = rawValues[slot]; } } } } //snapping if (snap) { if (rawValues[slot] > 0f && controlValues[slot] < 0f) { controlValues[slot] = 0f; } if (rawValues[slot] < 0f && controlValues[slot] > 0f) { controlValues[slot] = 0f; } } //move value towards target value if (rawValues[slot] < 0f) { if (controlValues[slot] > rawValues[slot]) { controlValues[slot] -= speed * Time.deltaTime; if (controlValues[slot] < rawValues[slot]) { controlValues[slot] = rawValues[slot]; } } } if (rawValues[slot] > 0f) { if (controlValues[slot] < rawValues[slot]) { controlValues[slot] += speed * Time.deltaTime; if (controlValues[slot] > rawValues[slot]) { controlValues[slot] = rawValues[slot]; } } } if (speed == 0f) { controlValues[slot] = rawValues[slot]; } } } }
// Update is called once per frame private void Update() { if (m_pauseMenu != null && m_pauseMenu.isActiveAndEnabled) { return; } bool lastMoving = moving; Vector3 deltaPosition = Vector3.zero; if (moving) { currentSpeed += increaseSpeed * Time.deltaTime; } moving = false; if (Sinput.GetButtonRaw("Up")) { DoMove(ref deltaPosition, transform.forward); } if (Sinput.GetButtonRaw("Down")) { DoMove(ref deltaPosition, -transform.forward); } if (Sinput.GetButtonRaw("Right")) { DoMove(ref deltaPosition, transform.right); } if (Sinput.GetButtonRaw("Left")) { DoMove(ref deltaPosition, -transform.right); } if (Sinput.GetButtonRaw("FlyUp")) { DoMove(ref deltaPosition, transform.up); } if (Sinput.GetButtonRaw("FlyDown")) { DoMove(ref deltaPosition, -transform.up); } if (moving) { if (moving != lastMoving) { currentSpeed = initialSpeed; } transform.position += deltaPosition * currentSpeed * Time.deltaTime; } else { currentSpeed = 0f; } Vector3 pos = transform.position; pos.x = Mathf.Clamp(pos.x, -30f, 30f); pos.y = Mathf.Clamp(pos.y, 1f, 15f); pos.z = Mathf.Clamp(pos.z, -20f, 60f); transform.position = pos; if (Sinput.GetButtonRaw("Fire2")) { Vector3 eulerAngles = transform.eulerAngles; eulerAngles.x += -Sinput.GetAxis("Look Vertical") * m_cursorSensitivity; eulerAngles.y += Sinput.GetAxis("Look Horizontal") * m_cursorSensitivity; transform.eulerAngles = eulerAngles; } }
private void UpdateMovement() { Vector3 input = Vector3.zero; float df = 0; if (isAllowedToMove) { input = new Vector3(Sinput.GetAxis(strafeAxis), 0, Sinput.GetAxis(forwardsAxis)); if (input.sqrMagnitude > 1) { input.Normalize(); } if (input.sqrMagnitude == 0) { isSprinting = false; // stop sprinting when we stopped trying to move } df = Sinput.GetAxis(turnAxis) * turnSpeed * Time.fixedDeltaTime; transform.Rotate(0, df, 0); isSprinting |= Sinput.GetButton(sprintButton); // if we're sprinting stay sprinting float currspeed = walkSpeed * (isSprinting ? sprintMultiplier : 1) * Time.fixedDeltaTime; Vector3 dpos = input * currspeed; characterController.SimpleMove(transform.forward * dpos.z + transform.right * dpos.x); } else { characterController.SimpleMove(Vector3.zero); // move in place to stop the walking sound effects } // move leg position! if (characterController.velocity.sqrMagnitude > 0.1 || Mathf.Abs(df) > 0 || moveToRestingPosition) { tiltBody.localRotation = Quaternion.Euler(input.z * tiltMultiplier, 0, -input.x * tiltMultiplier); // then we adjust the timer! legTimer += Time.fixedDeltaTime; legTimer %= timePerLegGroup * legGroups.Count; int currLeg = Mathf.FloorToInt(legTimer / timePerLegGroup); if (previousLegGroup != currLeg) { // disable the previous legs for (int i = 0; i < legGroups[previousLegGroup].legs.Count; i++) { legGroups[previousLegGroup].legs[i].StopLeg(); } // now update the current legs! for (int i = 0; i < legGroups[currLeg].legs.Count; i++) { legGroups[currLeg].legs[i].MoveLeg(timePerLegGroup); // for now just move it directly } previousLegGroup = currLeg; } } }