/// <summary> /// Update the state in which the player gets controlled by another entity than the player /// </summary> private void UpdatePuppetState() { var velocity = new Vector3(_body.velocity.x, _body.velocity.y, 0); // in puppet mode the player's 'cursor' is in the direction the player is walking var cursorPosition = transform.position + velocity; var animationState = AnimationStateDecisionTree.GetAnimationState(transform.position, cursorPosition, velocity, _idleSpeed); _animator.SetInteger(AnimatorParameterNames.AnimationState, animationState); }
/// <summary> /// Update the state where the player is in control of the character /// </summary> private void UpdatePlayerControlledState() { var velocity = UpdateVelocity(); var cursorPosition = GetCursorPosition(); var animationState = AnimationStateDecisionTree.GetAnimationState(transform.position, cursorPosition, velocity, _idleSpeed); if (_currentWeaponIndex != -1) { UpdateAttack(cursorPosition, _weapons[_currentWeaponIndex]); } _animator.SetInteger(AnimatorParameterNames.AnimationState, animationState); }
public void Update() { var animationState = AnimationState.MovingBackwardFacingRight; _body.velocity = Vector3.zero; // only do something if the player is alive if (_player != null && _player.activeInHierarchy) { // select a weapon if no weapon is being held if (_weapon == null) { _weapon = SelectWeapon(); } // if a weapon is armed and it can fire (this will cause the monster to // stop and fire) if (_weapon && _weapon.IsCooldownOver()) { AimWeapon(_weapon, _player); // if in range attack the player if (_weapon.IsInRange(_player)) { AttackPlayer(); } else { // if not move towards the player var movementDirection = (_player.transform.position - transform.position); movementDirection.z = 0; movementDirection.Normalize(); _body.velocity = movementDirection * _maxSpeed; } } animationState = AnimationStateDecisionTree.GetAnimationState(transform.position, _player.transform.position, _body.velocity, 0.4f); } _animator.SetInteger(AnimatorParameterNames.AnimationState, animationState); }