public bool TryParry() { var nearestTarget = TargetManager.FindClosest(transform.position); var agentAnimationMessages = nearestTarget.transform.GetComponentInChildren <AnimationMessages>(); var agentAnimator = nearestTarget.transform.GetComponentInChildren <Animator>(); var agent = nearestTarget.transform.GetComponent <BasicAgent>(); if (agentAnimationMessages.ParryProcess.State) { Parry.SetActive(true); var dir = transform.position - nearestTarget.transform.position; dir.Normalize(); Parry.transform.position = nearestTarget.transform.position + dir * 1; Parry.transform.position += new Vector3(0, 1, 0); agentAnimator.SetTrigger("Impact"); agent.Data.Cooldown.Run(0.5f); return(true); } return(false); }
private void UpdateMovement() { _dir = new Vector3(Input.GetAxis("Horizontal"), 0, Input.GetAxis("Vertical")); var rawDir = new Vector3(Input.GetAxisRaw("Horizontal"), 0, Input.GetAxisRaw("Vertical")); if (Guarding) { var nearestTarget = TargetManager.FindClosest(transform.position); if (nearestTarget != null) { var dir = nearestTarget.transform.position - transform.position; dir.Normalize(); transform.forward = Vector3.Lerp(transform.forward, dir, 3 * Time.deltaTime); } AnimatorController.Guard(true); } else { AnimatorController.Guard(false); } // Rotation var rotation = _dir.sqrMagnitude != 0 ? Quaternion.LookRotation(_dir) : transform.rotation; if (_dir.sqrMagnitude > 0 && !Guarding) { transform.rotation = Quaternion.Lerp(transform.rotation, rotation, 8f * Time.deltaTime); } // Movement var lookDotProduct = Quaternion.Dot(transform.rotation, rotation); if (Mathf.Abs(lookDotProduct) > 0.9f || Guarding) { transform.position += _dir * Time.deltaTime * MoveSpeed; } var anyMovementKey = Input.GetKeyDown(KeyCode.D) || Input.GetKeyDown(KeyCode.A) || Input.GetKeyDown(KeyCode.W) || Input.GetKeyDown(KeyCode.S); if (anyMovementKey && Guarding) { if (_lastMovementKeyPressed != null) { var _lastMovementTimeElapsed = Time.time - _lastMovementKeyPressed; if (_lastMovementTimeElapsed <= 0.2f && _dashDir == rawDir) { var dashToPosition = transform.position + rawDir * 2; transform.GoTo(dashToPosition, 0.1F); Cooldown.Run(duration: 0.2F); // Instead we should put an event EffectController.PlayDash(0.5F); } if (!rawDir.Equals(_dashDir)) { _dashDir = rawDir; } } _lastMovementKeyPressed = Time.time; } var x = Mathf.Abs(_dir.x); var z = Mathf.Abs(_dir.z); AnimatorController.SetMovement(x > z ? x : z); }