public override void Activate(Vector2 orientation) { if (comboTimeLeft > 0) { nextAttack.Activate(orientation); } else { base.Activate(orientation); comboTimeLeft = maxTimeToCombo; particleEffect.Play(); } }
void Update() { float dt = Time.deltaTime; bool isGrounded = controller.isGrounded; bool landed = !wasGrounded && isGrounded; // Dummy input. input.x = Input.GetAxis(XAxis) + mobileInput.x; input.y = Input.GetAxis(YAxis) + mobileInput.y; bool inputJumpStop = Input.GetButtonUp(JumpButton); bool inputJumpStart = Input.GetButtonDown(JumpButton); bool doCrouch = (isGrounded && input.y < -0.5f) || (forceCrouchEndTime > Time.time); bool doJumpInterrupt = false; bool doJump = false; bool hardLand = false; /* * if (landed) * { * if (-velocity.y > forceCrouchVelocity) * { * hardLand = true; * doCrouch = true; * forceCrouchEndTime = Time.time + forceCrouchDuration; * } * } */ if (!doCrouch) { if (isGrounded) { if (inputJumpStart | mobileJumpStart) { doJump = true; mobileJumpStop = false; } } else { doJumpInterrupt = (inputJumpStop && Time.time < minimumJumpEndTime) || (mobileJumpStop && Time.time < minimumJumpEndTime); } } // Dummy physics and controller using UnityEngine.CharacterController. Vector3 gravityDeltaVelocity = Physics.gravity * gravityScale * dt; if (doJump) { velocity.y = jumpSpeed; minimumJumpEndTime = Time.time + minimumJumpDuration; } else if (doJumpInterrupt) { if (velocity.y > 0) { velocity.y *= jumpInterruptFactor; } } velocity.x = 0; if (!doCrouch) { if (input.x != 0) { velocity.x = Mathf.Abs(input.x); velocity.x *= Mathf.Sign(input.x) * runSpeed; } } if (!isGrounded) { if (wasGrounded) { if (velocity.y < 0) { velocity.y = 0; } } else { velocity += gravityDeltaVelocity; } } controller.Move(velocity * dt); // Animation if (playerHealth.currentHealth <= 0) { targetAnimation = lose; runSpeed = 0; visuals.localPosition = Vector2.Lerp(visuals.localPosition, new Vector2(fallBack, 0f), 2 * Time.deltaTime); } else { if (isGrounded) { if (characterSkill.skillActive) { targetAnimation = characterSkill.targetAnimation; characterSkill.Activate(); } else { targetAnimation = run; } } else { if (characterSkill.skillActive) { targetAnimation = characterSkill.targetAnimation; characterSkill.Activate(); } else { targetAnimation = velocity.y > 0 ? jump : fall; } } } // Animation transition if (previousTargetAnimation != targetAnimation) { Spine.Animation transition = null; if (transitions != null && previousTargetAnimation != null) { transition = transitions.GetTransition(previousTargetAnimation, targetAnimation); } if (transition != null) { skeletonAnimation.AnimationState.SetAnimation(0, transition, false).MixDuration = 0.10f; skeletonAnimation.AnimationState.AddAnimation(0, targetAnimation, true, 0f); if (!characterSkill.skillActive) { characterSkill.Invoke("DelayedDeactivate", characterSkill.skillEndTransition); } } else if (playerHealth.currentHealth <= 0) { skeletonAnimation.AnimationState.SetAnimation(0, targetAnimation, false); } else { skeletonAnimation.AnimationState.SetAnimation(0, targetAnimation, true); } } previousTargetAnimation = targetAnimation; // Effects if (doJump) { jumpAudioSource.Stop(); jumpAudioSource.Play(); } if (landed) { if (hardLand) { hardfallAudioSource.Play(); } else { footstepHandler.Play(); } landParticles.Emit((int)(velocity.y / -9f) + 2); } wasGrounded = isGrounded; }
public void Update() { //if (timeToNextCheck <= 0) //{ // timeToNextCheck = maxTimeToNextCheck; //} //else //{ // timeToNextCheck -= Time.deltaTime; //} if (state == ActorState.Idle || state == ActorState.Moving) { if (directionTime <= 0) { Vector3 distance = this.transform.position - target.transform.position; if (((Mathf.Abs(distance.x) < attackRange && Mathf.Abs(distance.y) < attackWidthRange) || (Mathf.Abs(distance.y) < attackRange && Mathf.Abs(distance.x) < attackWidthRange)) && attackTime <= 0) { //attack Vector3 distanceVector = this.transform.position - target.transform.position; if (Mathf.Abs(distanceVector.x) > Mathf.Abs(distanceVector.y)) { orientation = new Vector2(distanceVector.x > 0 ? -1 : 1, 0); } else { orientation = new Vector2(0, distanceVector.y > 0 ? -1 : 1); } rb.velocity = new Vector2(0, 0); attackTime = attackCooldown; state = ActorState.Attacking; skill.Activate(orientation); StartCoroutine(Flash(skill.activationTime, 1, Color.yellow)); directionTime = directionTimeMax; } else { GetNewVelocity(); if (rb.velocity.magnitude > 0.01f) { state = ActorState.Moving; } else { state = ActorState.Idle; } if (Mathf.Abs(rb.velocity.x) > Mathf.Abs(rb.velocity.y)) { orientation = new Vector2(rb.velocity.x > 0 ? 1 : -1, 0); } else if (Mathf.Abs(rb.velocity.y) > Mathf.Abs(rb.velocity.x)) { orientation = new Vector2(0, rb.velocity.y > 0 ? 1 : -1); } } } else { directionTime -= Time.deltaTime; attackTime -= Time.deltaTime; } } }