/// <summary> /// Regarde en direction de la cible /// </summary> private void LookAtTarget() { // si j'ai une cible if (MyTarget != null) { // Direction de la cible Vector2 directionToTarget = (MyTarget.transform.position - transform.position).normalized; // Ma direction Vector2 myDirection = new Vector2(MyAnimator.GetFloat("x"), MyAnimator.GetFloat("y")); // Angle de vision de la cible float angleToTarget = Vector2.Angle(myDirection, directionToTarget); if (angleToTarget > fieldOfView / 2) { // Ajuste la direction MyAnimator.SetFloat("x", directionToTarget.x); MyAnimator.SetFloat("y", directionToTarget.y); // Actualise la direction updateDirection = true; } } }
private void OnStepUpdate() { Vector3 tmpZ = MyAnimator.GetFloat("Z") * MyModel.transform.forward; Vector3 tmpX = MyAnimator.GetFloat("X") * MyModel.transform.right; _stepVec = (tmpX + tmpZ) * 6; BLockmoving = true; MovingVec = Vector3.zero; }
public void Move() { if ((GetDirection().x > 0 && transform.position.x < RightEdge.position.x) || (GetDirection().x < 0 && transform.position.x > LeftEdge.position.x)) { transform.Translate(GetDirection() * (MyAnimator.GetFloat("speed") * movementSpeed * Time.deltaTime), Space.World); } else if (currentState is PatrolState) { Flip(); } else if (currentState is RangedState) { RemoveTarget(); } }
// Will handle the top down movement of the player private void HandleMovement() { float horizontal = Input.GetAxis("Horizontal"); float vertical = Input.GetAxis("Vertical"); MyRigidBody2D.velocity = new Vector2(horizontal * movementSpeed, vertical * movementSpeed); MyAnimator.SetFloat("SpeedX", horizontal); MyAnimator.SetFloat("SpeedY", vertical); if (MyAnimator.GetFloat("SpeedX") == 0 && MyAnimator.GetFloat("SpeedY") == 0 && isCharging == false) { MyAnimator.SetBool("IsIdle", true); } else { MyAnimator.SetBool("IsIdle", false); } }
private void LookAtTarget() { if (MyTarget != null) { Vector2 directionToTarget = (MyTarget.transform.position - transform.position).normalized; Vector2 faceing = new Vector2(MyAnimator.GetFloat("x"), MyAnimator.GetFloat("y")); float angleToTarget = Vector2.Angle(faceing, directionToTarget); if (angleToTarget > fieldOfView / 2) { MyAnimator.SetFloat("x", directionToTarget.x); MyAnimator.SetFloat("y", directionToTarget.y); updateDirection = true; } } }
//设置走路动画 private float SetMoveAnim(int num) { MyAnimator.SetFloat("Z", Mathf.Lerp(MyAnimator.GetFloat("Z"), num, 0.1f)); return MyAnimator.GetFloat("Z"); }