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); }
public void HandleLeftRightMovement() { hInput = Sinput.GetAxisRaw("Horizontal"); spriteRenderer.flipX = hInput != 0 ? hInput < 0 : spriteRenderer.flipX; //this sorta weird setup means that the player can still MOVE really fast (if propelled by external forces) //its just that he cant go super fast just by player input alone //force should be clamped so it doesnt let velocity extend past currentSpeed var force = accel * hInput * Time.deltaTime * 100; force = Mathf.Clamp(force + velocity.x, -currentSpeed, currentSpeed) - velocity.x; //basically making sure the adjusted force of the input doesn't act against the input itself if (Mathf.Sign(force) == Mathf.Sign(hInput)) { velocity.x += force; } if (Mathf.Abs(hInput) < 0.01f) { velocity.x *= 0.8f; } }
void FixedUpdate() { float lh = Sinput.GetAxisRaw("Horizontal"); float lv = Sinput.GetAxisRaw("Vertical"); Move(lh, lv); FlashlightBob(); }
// Update is called once per frame void Update() { //get player input for motion Vector3 motionInput = Sinput.GetVector("Horizontal", "", "Vertical", playerSlot); //we want to move like, three times as much as this motionInput *= 3f; //gravity yMotion -= Time.deltaTime * 10f; motionInput.y = yMotion; //move our character controller now characterController.Move(motionInput * Time.deltaTime); //landing/jumping if (characterController.isGrounded) { yMotion = -0.05f; if (Sinput.GetButtonDown("Jump", playerSlot)) { //we pressed jump while on the ground, so we jump! yMotion = 5f; } } //aiming Vector3 aimDir = Vector3.zero; aimDir.x = Sinput.GetAxisRaw("Horizontal", playerSlot); aimDir.z = Sinput.GetAxisRaw("Vertical", playerSlot); if (aimDir.magnitude > 0.4f) { //inputs are strong enough, lets look in the aim direction lookDirection = aimDir.normalized; Quaternion fromRotation = transform.rotation; transform.LookAt(transform.position + lookDirection); transform.rotation = Quaternion.Slerp(fromRotation, transform.rotation, Time.deltaTime * 10f); } //make sure our display text always faces the same way playerSlotDisplay.transform.eulerAngles = Vector3.zero; //shooting bulletCooldown -= Time.deltaTime; if (Sinput.GetButton("Fire1", playerSlot) && bulletCooldown <= 0f) { bulletCooldown = 0.2f; GameObject newBullet = (GameObject)GameObject.Instantiate(bulletPrefab); newBullet.transform.position = gunTransform.position; newBullet.transform.rotation = gunTransform.rotation; newBullet.GetComponent <BulletScript>().moveDir = gunTransform.forward; } if (Sinput.GetButton("Fire2", playerSlot) && bulletCooldown <= 0f) { bulletCooldown = 0.05f; GameObject newBullet = (GameObject)GameObject.Instantiate(bulletPrefab); newBullet.transform.position = gunTransform.position; newBullet.transform.rotation = gunTransform.rotation; newBullet.transform.localScale = Vector3.one * 0.3f; newBullet.GetComponent <BulletScript>().moveDir = gunTransform.forward; newBullet.GetComponent <BulletScript>().moveSpeed = 30f; newBullet.GetComponent <BulletScript>().life = 0.33f; } }