private void HandleMovement(float horizontal) { if (MyRigidbody.velocity.y < 0) { MyAnimator.SetBool("land", true); } if (!Attack && !Slide && !Crouch || (OnGround || airControl)) { MyRigidbody.velocity = new Vector2(horizontal * movementSpeed, MyRigidbody.velocity.y); } if (Jump && MyRigidbody.velocity.y == 0 && !Crouch) { MyRigidbody.AddForce(new Vector2(0, jumpForce)); } ////player boundaries on X axis //if (transform.position.x <= -4.3f) //{ // transform.position = new Vector2(-4.3f, transform.position.y); //} //else if (transform.position.x >= 27.75f) //{ // transform.position = new Vector2(27.75f, transform.position.y); //} MyAnimator.SetFloat("speed", Mathf.Abs(horizontal)); }
public void LaunchPlayer() { launch = true; MyRigidbody.velocity = new Vector2(catapultLaunchX, catapultLaunchY); gameObject.layer = 11; MyAnimator.SetBool("land", true); }
private bool IsGrounded(Rigidbody2D MyRigidbody) { if (MyRigidbody.velocity.y <= 0.2) { //MyRigidbody.velocity += Vector2.up * Physics2D.gravity.y * (fallMultiplier - 1) * Time.deltaTime; foreach (Transform point in groundPoints) { //Gets the colliders on the player's feet Collider2D[] colliders = Physics2D.OverlapCircleAll(point.position, groundRadius, groundMask); for (int i = 0; i < colliders.Length; i++) { if (colliders[i].gameObject != gameObject && (colliders[i].gameObject.CompareTag("Floor") || ((this.gameObject.layer == 9 && colliders[i].gameObject.layer == 8) || (this.gameObject.layer == 8 && colliders[i].gameObject.layer == 9)))) { //If the colliders collide with something else than the player, then the players is grounded canJump = true; isJumping = false; MyAnimator.ResetTrigger("Jump"); if (MyAnimator.GetBool("Land")) { MyAnimator.SetBool("Land", false); AudioManager.instance.Play(gameObject.name + "Land"); StartCoroutine("LandEffect"); } return(true); } } } } return(false); }
private void HandleMovement(float horizontal, float vertical) { if (isRunning) { movementSpeed = 5f; } else { movementSpeed = 2f; } if (IsFalling) { gameObject.layer = 11; MyAnimator.SetBool("land", true); } if (!Attack && !Slide && (OnGround || airControl)) { MyRigidbody.velocity = new Vector2(horizontal * movementSpeed, MyRigidbody.velocity.y); } if (Jump && MyRigidbody.velocity.y == 0 && !OnLadder) { MyRigidbody.AddForce(new Vector2(0, jumpForce)); } if (OnLadder) { MyAnimator.speed = vertical != 0 ? Mathf.Abs(vertical) : Mathf.Abs(horizontal); MyRigidbody.velocity = new Vector2(horizontal * climbSpeed, vertical * climbSpeed); } MyAnimator.SetFloat("speed", Mathf.Abs(horizontal)); }
void Update() { CurrentTime += Time.deltaTime; if (!IsMoving) { if (CurrentTime > IdleInterval) { Move(); MyAnimator.SetBool(Parameter, true); CurrentTime = 0; IsMoving = true; } } else { if (CurrentTime > MoveInterval) { MyAnimator.SetBool(Parameter, false); CurrentTime = 0; IsMoving = false; MyRigidBody2D.velocity = Vector2.zero; } } OldVelocity = MyRigidBody2D.velocity; }
public override void MakeAction() { if (!MyAnimator.GetBool("isWalking")) { MyAnimator.SetBool("isWalking", true); } }
private void HandleMovement(float horizontal) { if (MyRigidbody.velocity.y < 0 && !OnGround) { MyAnimator.SetBool("falling", true); MyAnimator.SetBool("jump bool", false); } if (MyRigidbody.velocity.y == 0 && Time.time - jumpTime > 0.10) { MyAnimator.SetBool("jump bool", false); } if (!MyAnimator.GetBool("slide") && (OnGround || airControl)) { MyRigidbody.velocity = new Vector2(horizontal * movementSpeed, MyRigidbody.velocity.y); } if (OnGround && Jump) { OnGround = false; MyRigidbody.AddForce(new Vector2(0, jumpForce)); } MyAnimator.SetFloat("speed", Mathf.Abs(horizontal)); }
public override void Dead() { base.Dead(); StopMove(); Moveable = false; MyAnimator.SetBool("Deadb", true); }
private void HandleInput() // where we put in controls (we can use this to make 2-3 player games { if (Input.GetKeyDown(KeyCode.X)) { MyAnimator.SetTrigger("jump"); } if (Input.GetKeyDown(KeyCode.Z)) { MyAnimator.SetTrigger("attack"); } if (Input.GetKeyDown(KeyCode.C)) { MyAnimator.SetTrigger("slide"); } if (Input.GetKey(KeyCode.S)) { MyAnimator.SetBool("crouch", true); } if (Input.GetKeyDown(KeyCode.V)) { MyAnimator.SetTrigger("throw"); } }
private void HandleWallSliding() { wallDirX = (Controller.collisionInfo.left) ? -1 : 1; wallSliding = CheckWallSliding(); MyAnimator.SetBool("WallSliding", wallSliding); if (wallSliding) { velocity.y = Mathf.Max(-wallSlideSpeedMax, velocity.y); if (stickToWall) { velocityXSmoothing = 0f; velocity.x = 0f; if (directionalInput.x != wallDirX && directionalInput.x != 0f) { wallStickTimer.UpdateClock(); } else { wallStickTimer.ResetTimer(); } } else { stickToWall = true; } } }
public override IEnumerator TakeDamage() { if (!enemyCanvas.isActiveAndEnabled) { enemyCanvas.enabled = true; } if (canDamage) { healthStat.CurrentVal -= 10; canDamage = false; if (!IsDead) { MyAnimator.SetBool("damage", true); StartCoroutine(TransitionAfterDelay(0.12f)); } else { MyAnimator.SetBool("die", true); enemyCanvas.enabled = false; yield return(null); } } }
private void HandleMovement(float horizontal) { if (MyRigidBody.velocity.y < 0) { MyAnimator.SetBool("land", true); } if (!Attack && !Slide && !Dash && (OnGround || airControl) && !knockbackFlag && !playerDeath)// means you can't move during the !EVENT { MyRigidBody.velocity = new Vector2(horizontal * movementSpeed, MyRigidBody.velocity.y); } if (Land && Attack) //if we are in the process of landing { MyRigidBody.AddForce(new Vector2(-1 * MyRigidBody.velocity.x * landingSpeed, 0)); //add a small force in the opposite direction that the player is moving if ((MyRigidBody.velocity.x == 0)) //or our player has stopped moving { Land = false; //consider the landing to be complete } } if (Jump && MyRigidBody.velocity.y == 0 && !Dash) { MyRigidBody.AddForce(new Vector2(0, jumpForce));//causes you to jump 0=x axis, jumpFroce=yaxis } MyAnimator.SetFloat("speed", Mathf.Abs(horizontal)); }
public override void Death() { MyAnimator.SetBool("Alive", true); healthStat.CurrentVal = healthStat.MaxVal; MyRigidbody.velocity = Vector2.zero; transform.position = startPos; }
//new HandleMovement private void HandleMovement(float horizontal) { if (MyRigidbody.velocity.y < 0) { MyAnimator.SetBool("land", true); } // causes unable to jump when tapping fast //if (Jump && OnGround && (MyRigidbody.velocity.y == 0)) // || MyRigidbody.velocity.y > -8.8 //if (Jump && GroundCheck() && btnJumping == true) // || MyRigidbody.velocity.y > -8.8 //{ // MyRigidbody.velocity = Vector2.up * jumpVelocity; // //source.PlayOneShot(jumpSound, 0.13F); //} if (!Attack && !Slide && (GroundCheck() || airControl)) // add one for aircontrool and in air and slow it down { MyRigidbody.velocity = new Vector2(horizontal * movementSpeed, MyRigidbody.velocity.y); } if (Attack && !Slide && (GroundCheck() || airControl)) { MyRigidbody.velocity = new Vector2(horizontal * movementSpeed / 1.8f, MyRigidbody.velocity.y); } //if (Jump && GroundCheck() && (MyRigidbody.velocity.y < 0)) // || MyRigidbody.velocity.y > -8.8 //{ // Debug.Log("tried to jump but velocity Y is < 0 = " + MyRigidbody.velocity.y); //} MyAnimator.SetFloat("speed", Mathf.Abs(horizontal)); }
public override IEnumerator TakeDamage() { if (!MyAnimator.GetBool("slide")) { if (canDamage) { healthStat.CurrentVal -= 10; canDamage = false; if (!IsDead) { MyAnimator.SetBool("damage", true); StartCoroutine(IndicateImmortal()); StartCoroutine(AnimatorTransitionTimer(0.14f)); StartCoroutine(TransitionAfterDelay(1.2f)); } else { MyAnimator.SetBool("die", true); Death(); //MyRigidbody.velocity.x = Vector2.zero; yield return(null); } } } }
private void ChargeBreak() { Moveable = true; isCharging = false; MyAnimator.SetBool("isCharing", false); indicator.SetIndicatorActive(false); }
public void ReleaseSpores(bool releaseinconeorcircle) { //if (!Alive) return; SporeAttackTime = Time.time; AttackTime = Time.time; MyAnimator.SetBool("WingUp", true); //Create a Cloud of Spores that slows the astronaut SporeExplosion.Play(true); int subs = (5 + (Astronaut.AggressionLevel * 3)); for (int i = 0; i < (subs); i++) { JungleTreeProjectile proj = GameObject.Instantiate(SporePrefab, this.transform.position, this.transform.rotation).GetComponent <JungleTreeProjectile>(); // proj.transform.localScale = (this.transform.localScale * (.3f)); proj.DamageRatio = (1f * (1f / ((float)(subs)))); float af = (((float)i + (1 * (Random.value))) / ((float)(subs))); float ang = (releaseinconeorcircle ? 45f + (90f * af) : (360f * af)); proj.MyConstantForce.enabled = true; proj.MyRigidbody.velocity = ((new Vector2(Mathf.Cos((ang / 360f) * 2f * Mathf.PI), Mathf.Sin((ang / 360f) * 2f * Mathf.PI)) * 2.5f) * (((float)(i + 1)) / ((float)subs)) * (.5f + Random.value * 3f) * (1f + Astronaut.AggressionLevelF)); proj.MyConstantForce.force = (Random.insideUnitCircle.normalized * JungleTreeProjectile.WINDFORCEFACTOR); //proj } }
/// <summary> /// A co routine for attacking /// </summary> /// <returns></returns> private IEnumerator Attack(string spellName) { Transform currentTarget = MyTarget; //Creates a new spell, so that we can use the information form it to cast it in the game Spell newSpell = SpellBook.MyInstance.CastSpell(spellName); IsAttacking = true; //Indicates if we are attacking MyAnimator.SetBool("attack", IsAttacking); //Starts the attack animation foreach (GearSocket g in gearSockets) { g.MyAnimator.SetBool("attack", IsAttacking); } yield return(new WaitForSeconds(newSpell.MyCastTime)); //This is a hardcoded cast time, for debugging if (currentTarget != null && InLineOfSight()) { SpellScript s = Instantiate(newSpell.MySpellPrefab, exitPoints[exitIndex].position, Quaternion.identity).GetComponent <SpellScript>(); s.Initialize(currentTarget, newSpell.MyDamage, transform); } StopAttack(); //Ends the attack }
private bool IsGrounded() { if (rb2d.velocity.y <= 0) { foreach (Transform point in groundPoints) { Collider2D[] colliders = Physics2D.OverlapCircleAll(point.position, groundRadius, whatIsGround); for (int i = 0; i < colliders.Length; i++) { if (colliders[i].gameObject != gameObject) { MyAnimator.ResetTrigger("jump"); MyAnimator.SetBool("land", false); if (colliders[i].tag == "Platform") { transform.parent = colliders[i].gameObject.transform; } return(true); } } } } transform.parent = null; return(false); }
private void handleMovement(float horizontal) { if (rb2d.velocity.y < 0) { MyAnimator.SetBool("Land", true); } if (!MyAnimator.GetBool("slide") && !this.MyAnimator.GetCurrentAnimatorStateInfo(0).IsTag("Attack") && (isGrounded || airControl)) { rb2d.velocity = new Vector2(horizontal * speed, rb2d.velocity.y); } if (isGrounded && jump) { isGrounded = false; rb2d.AddForce(new Vector2(0, jumpForce)); MyAnimator.SetTrigger("Jump"); } if (slide && !this.MyAnimator.GetCurrentAnimatorStateInfo(0).IsName("Slide2")) { MyAnimator.SetBool("slide", true); } else if (!this.MyAnimator.GetCurrentAnimatorStateInfo(0).IsName("Slide2")) { MyAnimator.SetBool("slide", false); } MyAnimator.SetFloat("speed", Mathf.Abs(horizontal)); }
private void HandleMovement(float horizontal, float vertical) // handles movement of the player and sets conditions so actions cannot be over lapped { if (IsFalling) { MyAnimator.SetBool("Land", true); gameObject.layer = 11; } if (!Attack && !Slide && (OnGround || airControl)) { MyRigidBody.velocity = new Vector2(horizontal * movementSpeed, MyRigidBody.velocity.y); } if (Jump && MyRigidBody.velocity.y == 0 && !OnLadder) { MyRigidBody.AddForce(new Vector2(0, jumpforce)); } if (OnLadder) { MyAnimator.speed = vertical != 0 ? Mathf.Abs(vertical) : Mathf.Abs(horizontal); MyRigidBody.velocity = new Vector2(horizontal * climbSpeed, vertical * climbSpeed); } MyAnimator.SetFloat("speed", Mathf.Abs(horizontal)); }
// Will handle movement of the player private void HandleMovement() { float horizontal = Input.GetAxis("Horizontal"); float vertical = Input.GetAxis("Vertical"); var worldPosition = Camera.main.ScreenToWorldPoint(Input.mousePosition); Vector3 relativePoint = transform.InverseTransformPoint(worldPosition); MyAnimator.SetFloat("SpeedX", relativePoint.x); MyAnimator.SetFloat("SpeedY", relativePoint.y); inputMovement = new Vector2(horizontal, vertical); // Moves the player based on input * consistent time frame * speed withini the world space transform.Translate(inputMovement * Time.deltaTime * movementSpeed, Space.World); if (horizontal != 0 || vertical != 0) { MyAnimator.SetBool("walking", true); } else { MyAnimator.SetBool("walking", false); } }
private IEnumerator AttackShield(string spellName) { Transform currentTarget = MyTarget; Spell newSpell = SpellBook.MyInstance.CastSpell(spellName, this); if (MyMana.MyCurrentValue >= newSpell.MyManaCost) { MyAnimator.SetBool("attackShield", true); isAttackingShield = true; yield return(new WaitForSeconds(newSpell.MyCastTime)); //tempo de cast da magia //CastSpell (); if (currentTarget != null && InLineOfSight()) { SpellScript s = Instantiate(newSpell.MySpellPrefab, exitPoints [exitIndex].position, Quaternion.identity).GetComponent <SpellScript> (); //quaternion não deixar rotacionar s.Initialize(currentTarget, newSpell.MyDamage, transform); MyMana.MyCurrentValue -= newSpell.MyManaCost; } StopAttackShield(); } }
private void HandleMovement(float horizontal) { if (myRigidbody.velocity.y < 0) { MyAnimator.SetBool("land", true); } if (!MyAnimator.GetBool("slide") && (isGrounded || airControl)) { myRigidbody.velocity = new Vector2(horizontal * movementSpeed, myRigidbody.velocity.y); } if (isGrounded && jump) { isGrounded = false; myRigidbody.AddForce(new Vector2(0, jumpForce)); MyAnimator.SetTrigger("jump"); } MyAnimator.SetFloat("speed", Mathf.Abs(horizontal)); if (slide && !this.MyAnimator.GetCurrentAnimatorStateInfo(0).IsName("Slide")) { MyAnimator.SetBool("slide", true); } else if (!this.MyAnimator.GetCurrentAnimatorStateInfo(0).IsName("Slide")) { MyAnimator.SetBool("slide", false); } }
private void HandleMovement(float horizontal) { if (IsFalling && gameObject.layer != 9) { gameObject.layer = 10; MyAnimator.SetBool("land", true); } //run if (!Attack && !Slide) { MyRigidbody.velocity = new Vector2(horizontal * movementSpeed, MyRigidbody.velocity.y); } if (OnGround && Jump) { Debug.Log(Jump); Debug.Log(OnGround); if (this.MyAnimator.GetCurrentAnimatorStateInfo(0).IsTag("idle")) { MyRigidbody.velocity = (new Vector2(0, 50 * (jumpForce / MyRigidbody.mass))); } else if (this.MyAnimator.GetCurrentAnimatorStateInfo(0).IsTag("run")) { MyRigidbody.velocity = (new Vector2(horizontal * movementSpeed, 50 * (jumpForce / MyRigidbody.mass))); } } MyAnimator.SetFloat("speed", Mathf.Abs(horizontal)); }
public override IEnumerator TakeDamage() { if (!immortal) { if (actState != ActState.Defence) { stat.Health.CurrentVal -= 10; if (!IsDead) { MyAnimator.SetTrigger("damage"); //immortal = true; //StartCoroutine(IndicateImmortal()); yield return(new WaitForSeconds(immortalTime)); immortal = false; } else { MyAnimator.SetLayerWeight(1, 0); MyAnimator.SetTrigger("die"); } } else { MyAnimator.SetBool("defence", false); actState = ActState.Delayed; yield return(new WaitForSeconds(0.05f)); actState = ActState.StandBy; } } }
public override IEnumerator TakeDamage(int dmg) { if (!immortal) { healthBar.CurrentValue -= dmg; canRegen = false; lastTimeTakenDmg = 0; if (!IsDead && !gm.IsPvp) { immortal = true; StartCoroutine(IndicateImmortal()); if (!Attack) { MyAnimator.SetBool("TakeDmg", true); } yield return(new WaitForSeconds(immortalTime)); immortal = false; } else { if (Dead != null) { Dead(); } } } }
private void HandleMovement(float horizontal) { if (MyRigidbody.velocity.y < 0) { MyAnimator.SetBool("land", true); } if (!Attack && !Slide && (OnGround || airControl)) { MyRigidbody.velocity = new Vector2(horizontal * movementSpeed, MyRigidbody.velocity.y); } if (Input.GetKeyDown(KeyCode.UpArrow) && !OnGround && canDoubleJump) { MyRigidbody.AddForce(new Vector2(0, jumpForce)); canDoubleJump = false; } else if (Input.GetKeyDown(KeyCode.UpArrow) && OnGround) { MyRigidbody.AddForce(new Vector2(0, jumpForce)); canDoubleJump = true; } MyAnimator.SetFloat("speed", Mathf.Abs(horizontal)); // Seteaza parametrul speed al animatorului in 1 --> se activeaza animatia run }
private void HandleMovement(float inputX) { if (MyRigidbody.velocity.y < -0.01f) { MyAnimator.SetBool("land", true); } if (actState.Equals(ActState.StandBy) && (OnGround || airControl)) { MyRigidbody.velocity = new Vector2(inputX * (base.stat.Spd.CurrentVal + runSpd), MyRigidbody.velocity.y); } if (Jump && Mathf.Abs(MyRigidbody.velocity.y) < 0.01f) { MyRigidbody.AddForce(new Vector2(0, jumpForce)); } if (Input.GetKey(KeyCode.LeftShift)) { runSpd = 2; } else { runSpd = 0; } MyAnimator.SetFloat("speed", Mathf.Abs(inputX)); }
protected virtual IEnumerator TransitionAfterDelay(float delay) { yield return(new WaitForSeconds(delay)); MyAnimator.SetBool("damage", false); canDamage = true; }