void Walk() { _walkStepParticles.enableEmission = true; walkDirection = Vector3.zero; if (ChainJam.GetButtonJustPressed(id, ChainJam.BUTTON.A)) { animator.SetBool("Charge", true); } if (!ChainJam.GetButtonPressed(id, ChainJam.BUTTON.A)) { animator.SetBool("Charge", false); } //lastStepTimer -= Time.deltaTime; //if (lastStepTimer <= 0) //{ // lastStepTimer = _stepTimeout; // StartCoroutine(VibrateStep(0.1f)); //} if (ChainJam.GetButtonPressed(id, ChainJam.BUTTON.LEFT)) { walkDirection.x = -1; } else if (ChainJam.GetButtonPressed(id, ChainJam.BUTTON.RIGHT)) { walkDirection.x = 1; } if (ChainJam.GetButtonPressed(id, ChainJam.BUTTON.DOWN)) { walkDirection.z = -1; } else if (ChainJam.GetButtonPressed(id, ChainJam.BUTTON.UP)) { walkDirection.z = 1; } rigidbody.AddForce(walkDirection.normalized * _walkSpeed); rigidbody.velocity = Vector3.ClampMagnitude(rigidbody.velocity, _maxWalkSpeed); transform.LookAt(transform.position + walkDirection); // switch back to standing if (walkDirection == Vector3.zero) { lastStepTimer = 0; currentWalkState = Stand; } }
void Stand() { _walkStepParticles.enableEmission = false; // play animation if (ChainJam.GetButtonJustPressed(id, ChainJam.BUTTON.DOWN) || ChainJam.GetButtonJustPressed(id, ChainJam.BUTTON.UP) || ChainJam.GetButtonJustPressed(id, ChainJam.BUTTON.LEFT) || ChainJam.GetButtonJustPressed(id, ChainJam.BUTTON.RIGHT)) { // switch to walking currentWalkState = Walk; lastStepTimer = _stepTimeout; } }
void Idle() { chargeTimer -= Time.deltaTime; if (chargeTimer <= 0 && ChainJam.GetButtonJustPressed(id, ChainJam.BUTTON.A)) { chargeForce = transform.forward * _chargeSpeed; rigidbody.AddForce(chargeForce, ForceMode.Impulse); chargeTimer = _chargeTimeout; _chargeStartParticles.Play(); animator.SetBool("Charge", true); StartCoroutine(Vibrate(0.3f, 1, 1)); } }
void Update() { // X axis if ( ChainJam.GetButtonPressed(GetComponent <Player>().id, ChainJam.BUTTON.LEFT)) { axisX -= sensitivityX * Time.deltaTime; } if (ChainJam.GetButtonPressed(GetComponent <Player>().id, ChainJam.BUTTON.RIGHT)) { axisX += sensitivityX * Time.deltaTime; } if ( !ChainJam.GetButtonPressed(GetComponent <Player>().id, ChainJam.BUTTON.LEFT) && !ChainJam.GetButtonPressed(GetComponent <Player>().id, ChainJam.BUTTON.RIGHT) ) { axisX -= axisX * inertiaX * Time.deltaTime; } if (axisX > 1f) { axisX = 1f; } if (axisX < -1f) { axisX = -1f; } // Y axis if ( ChainJam.GetButtonPressed(GetComponent <Player>().id, ChainJam.BUTTON.DOWN)) { axisY -= sensitivityY * Time.deltaTime; } if (ChainJam.GetButtonPressed(GetComponent <Player>().id, ChainJam.BUTTON.UP)) { axisY += sensitivityY * Time.deltaTime; } if ( !ChainJam.GetButtonPressed(GetComponent <Player>().id, ChainJam.BUTTON.UP) && !ChainJam.GetButtonPressed(GetComponent <Player>().id, ChainJam.BUTTON.DOWN) ) { axisY -= axisY * inertiaY * Time.deltaTime; } if (axisY > 1f) { axisY = 1f; } if (axisY < -1f) { axisY = -1f; } //and the actual rotation! float rotationX = transform.localEulerAngles.y + axisX; rotationY += axisY; rotationY = Mathf.Clamp(rotationY, minimumY, maximumY); transform.localEulerAngles = new Vector3(-rotationY, rotationX, 0); //jump if (ChainJam.GetButtonPressed(GetComponent <Player>().id, ChainJam.BUTTON.A)) { GetComponent <PlayerJump>().JumpToRandomPlatform(); } //shoot if (ChainJam.GetButtonJustPressed(GetComponent <Player>().id, ChainJam.BUTTON.B)) { Shoot(); } }