// Use this for initialization void Awake() { rapidFireTimerReset = rapidFireTimer; dashCounter = dashTime; dashCooldownCounter = dashCooldown; meleeTimerReset = meleeTimer; state = characterStates.IDLE; _weapons = GetComponentsInChildren<WeaponScript>(); }
void OnCollisionEnter(Collision other) { // Kill the player if they touch something deadly, aka light. if (other.gameObject.CompareTag("Death") && !dying) { StartCoroutine(Death()); } // Check if we have collided with a bounce pad if (other.gameObject.CompareTag("BouncePad")) { // Reset our velocity to zero. rb.velocity = Vector3.zero; // Create a new vector3 which takes our relative velocity then inverts the x and z axis so it gives a 'bounce' effect. Vector3 newVelocity = new Vector3(-other.relativeVelocity.x, other.relativeVelocity.y, -other.relativeVelocity.z).normalized; // Apply the force if (other.gameObject.GetComponent <BouncePad>()) { rb.AddForce(newVelocity * other.gameObject.GetComponent <BouncePad>().bounceForce); } else { rb.AddForce(newVelocity * launchPower * bounceModifier); } // Dont allow us to stop flying. canLand = false; StartCoroutine(landCooldown()); return; } else // Check if we have collided with a launch pad if (other.gameObject.CompareTag("LaunchPad")) { // Reset our velocity to zero. rb.velocity = Vector3.zero; // Take the normal of our collision and apply force in that direction. rb.AddForce(other.contacts[0].normal * launchPower * launchPadModifier); // Dont allow us to stop flying. canLand = false; StartCoroutine(landCooldown()); return; } else // Only remove velocity and set us idle if we are flying if (characterState == characterStates.Flying && canLand) { rb.velocity = Vector3.zero; characterState = characterStates.Idle; } }
void IdleInput() { // When the character is 'idle' (Stuck on a wall) let them launch off of it if (Input.GetKeyDown(launchKey)) { if (characterState == characterStates.Flying) { doubleJumped = true; rb.velocity = Vector3.zero; canLand = false; StartCoroutine(landCooldown()); } characterState = characterStates.Flying; rb.AddForce(charCamera.forward * launchPower); } }
public void Knockback() { value = characterStates.Knockback; }
public void WallCrawl() { value = characterStates.WallCrawl; }
public void StandardWalk() { value = characterStates.StandardWalk; }
public void WalkWithNoGravity() { value = characterStates.WalkWithNoGravity; }
public void NoGravityWalk() { value = characterStates.NoGravityWalk; }
void Update() { if (hasBottle) { bottledCloud.SetActive(true); } else { bottledCloud.SetActive(false); } // Do mouse look first. if (!dying) { SimulateMouse(); LockMouse(); } else { // Make the mouse visible when we die and unlock it. Cursor.lockState = CursorLockMode.None; Cursor.visible = true; } if (Vector3.Distance(transform.position, Vector3.zero) >= 300) { if (!dying) { StartCoroutine(Death()); } } // Black fade effect if (starting) { deathFade.color = deathFade.color - new Color(0, 0, 0, 1 * Time.deltaTime); if (deathFade.color.a <= 0) { starting = false; } } // Switch our states and call the function for each. switch (characterState) { case (characterStates.Idle): doubleJumped = false; IdleInput(); break; case (characterStates.Flying): if (hasBottle && !doubleJumped) { IdleInput(); } // Check if our velocity is less than the minimum wanted. if (rb.velocity.magnitude <= minimumVelocity && canLand) { characterState = characterStates.Idle; } break; } // Volume checks if (PlayerPrefs.GetFloat("MusicVolume", 1) != volumeSlider.value) { PlayerPrefs.SetFloat("MusicVolume", volumeSlider.value); music.volume = volumeSlider.value; PlayerPrefs.Save(); music.Stop(); music.Play(); } }
public void Idle() { value = characterStates.Idle; }
// Update is called once per frame void Update() { if(GetComponent<Renderer>().IsVisibleFrom(Camera.main) == false) { PlayerHealthScript health = this.GetComponent<PlayerHealthScript>(); health.Damage(1000); //Destroy(gameObject); } Vector3 velocity = _controller.velocity; float inputX = Input.GetAxis ("Horizontal"); //Vector2 shotDirection = Vector2.zero; //bool shoot = Input.GetButtonDown ("Fire1"); bool shoot = Input.GetKey (KeyCode.RightArrow) || Input.GetKey (KeyCode.LeftArrow); //Debug.Log ("Axis is: " + inputX.ToString ()); //Debug.Log ("State is : " + state); switch(state) { case characterStates.IDLE: //Debug.Log("IDLE"); if(dashEnabled == false) dashCooldownCounter--; else if(dashCounter < dashTime) dashCounter+= 0.5f; velocity.x = 0; //Debug.Log ("IDLE"); //animator.SetInteger("Melee", 0); if (inputX < 0) { //Debug.Log("IN IDLE: Input is: " + inputX + " changing to face LEFT"); velocity.x = -speed; animator.enabled = true; animator.SetInteger("Direction", 0); facingRight = false; state = characterStates.RUNNING; //animator.StopPlayback(); //gameObject.GetComponent<SpriteRenderer>().sprite = facingLeftImage; //shotDirection = -transform.right; } else if (inputX > 0) { //Debug.Log("IN IDLE: Input is: " + inputX + " changing to face RIGHT"); velocity.x = speed; animator.enabled = true; animator.SetInteger("Direction", 1); facingRight = true; state = characterStates.RUNNING; //animator.StopPlayback(); //gameObject.GetComponent<SpriteRenderer>().sprite = facingRightImage; //shotDirection = transform.right; } else { //Debug.Log("STopping playback"); //animator.SetInteger("Direction", 2); if(animator.GetCurrentAnimatorStateInfo(0).IsName("Lance _Land_ Shark Melee Right_") || animator.GetCurrentAnimatorStateInfo(0).IsName("Lance _Land_ Shark Melee Left_")) { //Debug.Log("in here yo"); } else { animator.enabled = false; if(facingRight) gameObject.GetComponent<SpriteRenderer>().sprite = facingRightImage; else gameObject.GetComponent<SpriteRenderer>().sprite = facingLeftImage; } } if (Input.GetAxis ("Jump") > 0 && _controller.isGrounded) { animator.enabled = false; if(facingRight) gameObject.GetComponent<SpriteRenderer>().sprite = jumpingRightImage; else gameObject.GetComponent<SpriteRenderer>().sprite = jumpingLeftImage; state = characterStates.JUMPING; velocity.y = Mathf.Sqrt (2f * jumpHeight * -gravity); } if (Input.GetKeyDown (KeyCode.DownArrow) == true) { AudioSource.PlayClipAtPoint (meleeAttack, transform.position, 0.5f); animator.enabled = true; //animator.SetInteger("Direction", 4); if(facingRight) animator.Play("Lance _Land_ Shark Melee Right_"); else animator.Play("Lance _Land_ Shark Melee Left_"); //animator.enabled = false; if (_weapons[2] != null && _weapons[3] != null) if(facingRight) _weapons[2].Attack(false); else _weapons[3].Attack(false); state = characterStates.MELEE; } if (shoot) { if (_weapons [0] != null && _weapons [1] != null) { if (inputX > 0) _weapons [0].Attack (false); else if (inputX < 0) _weapons [1].Attack (false); else { if (facingRight) _weapons [0].Attack (false); else _weapons [1].Attack (false); } } //_weapons[0].Attack(false, shotDirection); } //Debug.Log("Moving player"); velocity.y += gravity * Time.deltaTime; _controller.move (velocity * Time.deltaTime); break; case characterStates.RUNNING: //animator.StopPlayback(); //animator.SetInteger("Melee", 0); if(dashEnabled == false) dashCooldownCounter--; else if(dashCounter < dashTime) dashCounter+= 0.5f; //Debug.Log("Dashcounter: " + dashCounter); if(dashCooldownCounter <= 0) { dashEnabled = true; dashCooldownCounter = dashCooldown; dashCounter = dashTime; } velocity.x = 0; if (inputX < 0) { //Debug.Log("Input is: " + inputX + " changing to face LEFT"); velocity.x = -speed; //animator.StopPlayback(); animator.SetInteger("Direction", 0); facingRight = false; //gameObject.GetComponent<SpriteRenderer>().sprite = facingLeftImage; //shotDirection = -transform.right; } else if (inputX > 0) { //Debug.Log("Input is: " + inputX + " changing to face RIGHT"); velocity.x = speed; facingRight = true; //animator.StopPlayback(); animator.SetInteger("Direction", 1); //gameObject.GetComponent<SpriteRenderer>().sprite = facingRightImage; //shotDirection = transform.right; } else state = characterStates.IDLE; if (Input.GetKey (KeyCode.LeftShift) == true && dashEnabled) { if (inputX < 0) { velocity.x = -speed * 2; dashCounter--; if(dashCounter <= 0) dashEnabled = false; } else if(inputX > 0) { velocity.x = speed * 2; dashCounter--; if(dashCounter <= 0) dashEnabled = false; } //Debug.Log("DashCounter: " + dashCounter); } if (Input.GetAxis ("Jump") > 0 && _controller.isGrounded) { animator.enabled = false; if(facingRight) gameObject.GetComponent<SpriteRenderer>().sprite = jumpingRightImage; else gameObject.GetComponent<SpriteRenderer>().sprite = jumpingLeftImage; state = characterStates.JUMPING; velocity.y = Mathf.Sqrt (2f * jumpHeight * -gravity); } if (Input.GetKeyDown (KeyCode.DownArrow) == true) { AudioSource.PlayClipAtPoint (meleeAttack, transform.position, 0.5f); if(facingRight) animator.Play("Lance _Land_ Shark Melee Right_"); else animator.Play("Lance _Land_ Shark Melee Left_"); if (_weapons[2] != null && _weapons[3] != null) if(facingRight) _weapons[2].Attack(false); else _weapons[3].Attack(false); state = characterStates.MELEE; break; } if (shoot) { if (_weapons [0] != null && _weapons [1] != null) if (inputX > 0) _weapons [0].Attack (false); else if (inputX < 0) _weapons [1].Attack (false); else { if (facingRight) _weapons [0].Attack (false); else _weapons [1].Attack (false); } //_weapons[0].Attack(false, shotDirection); } if(state != characterStates.MELEE) { velocity.y += gravity * Time.deltaTime; _controller.move (velocity * Time.deltaTime); } break; case characterStates.JUMPING: //animator.SetInteger("Melee", 0); if(dashEnabled == false) dashCooldownCounter--; else if(dashCounter < dashTime) dashCounter+= 0.5f; // movement if (inputX < 0) { gameObject.GetComponent<SpriteRenderer>().sprite = jumpingLeftImage; velocity.x = -speed * 1f; animator.SetInteger("Direction", 0); facingRight = false; //animator.SetInteger("Direction", 1); //gameObject.GetComponent<SpriteRenderer>().sprite = facingLeftImage; //shotDirection = -transform.right; } else if (inputX > 0) { gameObject.GetComponent<SpriteRenderer>().sprite = jumpingRightImage; velocity.x = speed * 1f; animator.SetInteger("Direction", 1); facingRight = true; //animator.SetInteger("Direction", 0); //gameObject.GetComponent<SpriteRenderer>().sprite = facingRightImage; //shotDirection = transform.right; } else { //state = characterStates.IDLE; //break; } if (Input.GetKey (KeyCode.LeftShift) == true && dashEnabled) { if (inputX < 0) { velocity.x = -speed * 2; dashCounter--; if(dashCounter <= 0) dashEnabled = false; } else if(inputX > 0) { velocity.x = speed * 2; dashCounter--; if(dashCounter <= 0) dashEnabled = false; } } // shooting if (shoot) { if (_weapons [0] != null && _weapons [1] != null) if (inputX > 0) _weapons [0].Attack (false); else if (inputX < 0) _weapons [1].Attack (false); else { if (facingRight) _weapons [0].Attack (false); else _weapons [1].Attack (false); } //_weapons[0].Attack(false, shotDirection); } velocity.y += gravity * Time.deltaTime; // Take out -20 _controller.move (velocity * Time.deltaTime); if(_controller.isGrounded) state = characterStates.IDLE; break; case characterStates.MELEE: if(dashEnabled == false) dashCooldownCounter--; else if(dashCounter < dashTime) dashCounter+= 0.5f; if (Input.GetAxis ("Jump") > 0 && _controller.isGrounded) { } //animator.SetInteger("Direction", 4); //Debug.Log (meleeTimer); meleeTimer--; //Debug.Log("in melee"); if(meleeTimer <= 0) { //Debug.Log("End Melee"); state = characterStates.IDLE; meleeTimer = meleeTimerReset; } break; } var dist = (transform.position - Camera.main.transform.position).z; var leftBorder = Camera.main.ViewportToWorldPoint( new Vector3(0, 0, dist) ).x; var rightBorder = Camera.main.ViewportToWorldPoint( new Vector3(1, 0, dist) ).x; transform.position = new Vector3( Mathf.Clamp(transform.position.x, leftBorder, rightBorder), transform.position.y, transform.position.z ); }