private void HandleAnimatorChanges() { if (anim != null && ai != null) { if (state != animationState.BLOCKED_STATE) { if (ai.nav.velocity.magnitude == 0) { prevState = state; if (!ai.movingToPlayer) { // Means we haven't reached the player and are attacking state = animationState.IDLE; } } else { prevState = state; state = animationState.MOVING; } // Attacking state set by movement script - based on dist to player // Dead state set by controller script (health <= 0) } } }
private void SetAnimator() { if (climbing || falling) { if (AnimationState != animationState.falling) { AnimationState = animationState.falling; animator.SetTrigger("Falling"); } } else if (jumping) { if (AnimationState != animationState.jumping) { AnimationState = animationState.jumping; animator.SetTrigger("Jumping"); } } else if (Math.Abs(velocity.x) > 0) { if (AnimationState != animationState.running) { AnimationState = animationState.running; animator.SetTrigger("Running"); } } else { if (AnimationState != animationState.idle) { AnimationState = animationState.idle; animator.SetTrigger("Idle"); } } }
private void HandleAnimatorChanges() { if (anim != null && player != null) { if (state != animationState.BLOCKED_STATE) { if (player.velocity.magnitude == 0) { state = animationState.IDLE; } else { if (Input.GetKey(KeyCode.LeftShift)) { state = animationState.RUNNING; } else { state = animationState.WALKING; } } if (Input.GetKeyDown(Game_Manager.attack) && !inAnimatorState("Attack")) { isAttackKeyDown = true; } if (isAttackKeyDown && playerInventory.isWeaponVisible()) { state = animationState.ATTACKING; } // TODO: Can add other animation states here, like a pickup animation etc. } } }
private void AssignAnimatorBooleans() { // Sets all other animator booleans to false to set a single one to true foreach (AnimatorControllerParameter parameter in anim.parameters) { anim.SetBool(parameter.name, false); } switch (state) { case animationState.ATTACKING: anim.SetBool("isAttacking", true); GameObject.FindGameObjectWithTag("Weapon").GetComponent <BoxCollider>().isTrigger = false; // Blocked state represents a state where the current action has to finish before it becomes unblocked state = animationState.BLOCKED_STATE; break; case animationState.DEAD: anim.SetBool("isDead", true); state = animationState.BLOCKED_STATE; break; case animationState.RUNNING: anim.SetBool("isRunning", true); break; case animationState.WALKING: anim.SetBool("isWalking", true); break; case animationState.IDLE: anim.SetBool("isIdle", true); break; case animationState.BLOCKED_STATE: if (currAnimHasFinished()) { // Input buffering after animation finishes if (Input.GetAxis("Vertical") != 0) { if (Input.GetKey(KeyCode.LeftShift)) { state = animationState.RUNNING; } else { state = animationState.WALKING; } } else { state = animationState.IDLE; } isAttackKeyDown = false; GameObject.FindGameObjectWithTag("Weapon").GetComponent <BoxCollider>().isTrigger = true; } break; } }
//****************************************************************************************COROUTINE private IEnumerator AnimationPlay(animationState state) { float waitTime = 0; switch (state) { case animationState.Jump: rbd.useGravity = false; jumping = true; for (int i = 0; i < animations.Length; i++) { if (animations [i].name == "WildWestJump") { waitTime = animations [i].length; } } movement.y = 1 * speedJump; animController.SetTrigger("Jump"); Debug.Log("Velocity: " + rbd.velocity); yield return(new WaitForSecondsRealtime(waitTime * waitingTimeJump)); movement.y = gravity; yield return(new WaitForSecondsRealtime((waitTime - (waitTime * waitingTimeJump)))); jumping = false; animController.SetTrigger("StopJump"); waitTime = 0; break; case animationState.Slide: slide = true; for (int i = 0; i < animations.Length; i++) { if (animations [i].name == "WildWestRunnerSlide") { waitTime = animations [i].length; } } capCollider.height = capHeightCollider / 2; animController.SetTrigger("Slide"); yield return(new WaitForSecondsRealtime(waitTime)); slide = false; capCollider.height = capHeightCollider; animController.SetTrigger("StopSlide"); waitTime = 0; break; default: case animationState.Die: speedMovement = 0; animController.SetTrigger("Die"); Debug.Log("DIE"); yield return(new WaitForSecondsRealtime(4)); WildWestRunnerManager.instance.endGame(IMiniGame.MiniGameResult.LOSE); break; } }
// Use this for initialization void Start() { anim = GetComponent <Animator>(); player = GetComponent <Player_Movement>(); playerInventory = GetComponent <Player_Inventory>(); state = animationState.IDLE; }
// Use this for initialization void Start() { anim = GetComponent <Animator>(); ai = GetComponent <AI_Movement>(); controller = GetComponent <AI_Controller>(); state = animationState.IDLE; prevState = state; }
public void ChangeState(animationState changeTo) { currentAnimation = changeTo; if (changeTo == animationState.alert && animation.IsPlaying("attack")) { currentAnimation = animationState.attack; } }
public virtual void stateSelector() { if (timer == 0) { nowState = animationState.start; } else if (timer > 0 && timer < timeLength) { nowState = animationState.update; } else if (timer > timeLength) { nowState = animationState.end; } }
//Handles specifically jump inputs, seperated for readability void HandleJumpInput() { //when our character hits the ground, reset our states if (CharacterController.isGrounded) { isJumping = false; isGliding = false; } //jump action if (InputHandler.Instance.checkAction(InputHandler.actions.JUMP)) { //if we are gliding, another space will cancel the glide if (isGliding) { isGliding = false; return; } //if we arent already jumping if (isJumping != true) { isJumping = true; PlayerCharacterMotor.Instance.Jump(); } //else we are still in jumping state, and space was triggered. We can glide else { isGliding = true; } } //check and apply jump / glide animations if (isJumping) { playerAnimationState = animationState.Jumping; } if (isGliding) { playerAnimationState = animationState.Gliding; } }
private void HandleKnockBack() { if (Input.GetKeyDown(KeyCode.T)) { playerIsHit(false, true, -.5f, 80); } //TODO:, Replace this will external function call. MAKE SURE it occurs after update frame. or in late update. // We could just the colliders check in LateUpdate to process hits. if (Input.GetKeyDown(KeyCode.G)) { playerIsHit(true, true, -.5f, 30); } //updateCheck for if we are still knocked back or otherwise stunned. if (isStunned) { playerAnimationState = animationState.Stunned; } }
private void ChangeState() { if (!PlyCtr.inAction) { if (PlyCtr.isMoving) { animState = animationState.Walking; } else { animState = animationState.Idle; } } if (PlyCtr.isAttacking) { animState = animationState.Attacking; } if (PlyCtr.isDashing) { animState = animationState.Dashing; } }
private void AssignAnimatorBooleans() { // Sets all other animator booleans to false to set a single one to true foreach (AnimatorControllerParameter parameter in anim.parameters) { anim.SetBool(parameter.name, false); } switch (state) { case animationState.DEAD: anim.SetBool("isDead", true); state = animationState.BLOCKED_STATE; break; case animationState.ATTACKING: anim.SetBool("isAttacking", true); state = animationState.BLOCKED_STATE; break; case animationState.MOVING: anim.SetBool("isMoving", true); break; case animationState.IDLE: anim.SetBool("isIdle", true); break; case animationState.BLOCKED_STATE: if (currAnimHasFinished()) { prevState = state; state = animationState.IDLE; } break; } }
private void HandleJumpInput() { //avoid being able to jump when we are stunned if (isAnimationLocked || isStunned) { return; } //when our character hits the ground, reset our states if (CharacterController.isGrounded) { isJumping = false; isGliding = false; isDoubleJumping = false; isFalling = false; } else { isFalling = true; } //jump action if (Input.GetKeyDown(KeyCode.Space) || Input.GetKeyDown(KeyCode.Joystick1Button3) || Input.GetKeyDown(KeyCode.Joystick1Button1)) { //if we are gliding, another space will cancel the glide //if (isGliding) //{ // isGliding = false; // return; //} //if we arent already jumping if (isJumping == false && isFalling == false) { isJumping = true; thisMotor.Jump(false, xAxis); } //if we are still in jumping state, and space was triggered. We can glide else if (isJumping == true || isFalling == true) { if (isDoubleJumping != true) { isDoubleJumping = true; thisMotor.Jump(false, xAxis); } isGliding = true; } } //check and apply jump / glide animations if (isJumping) { playerAnimationState = animationState.Jumping; } if (isGliding) { playerAnimationState = animationState.Gliding; } if (isDoubleJumping) { playerAnimationState = animationState.DoubleJumping; } }
private void HandleActionInput() { //ESCAPE sequence, allows us to modify animationLocks manually for avoid errors if (Input.GetKey(KeyCode.F)) { isAnimationLocked = false; } if (Input.GetKey(KeyCode.E)) { isAnimationLocked = true; } //if we are anim locked, leave this function. no Actions can happen until we are no longer locked if (isAnimationLocked == true) { return; } playerAnimationState = animationState.Idling; //default state, only modified if some other action happens if (Input.GetKeyDown(KeyCode.A) || Input.GetAxis("Horizontal") < -deadZone) { Vector3 toRot = this.transform.rotation.eulerAngles; if (!isFalling) { this.transform.eulerAngles = new Vector3(this.transform.eulerAngles.x, -90, this.transform.eulerAngles.z); isFacingStageRight = false; } } if (Input.GetKeyDown(KeyCode.D) || Input.GetAxis("Horizontal") > deadZone) { Vector3 toRot = this.transform.rotation.eulerAngles; if (!isFalling) { this.transform.eulerAngles = new Vector3(this.transform.eulerAngles.x, 90, this.transform.eulerAngles.z); isFacingStageRight = true; } } if (Input.GetKey(KeyCode.W) || Input.GetKey(KeyCode.A) || Input.GetKey(KeyCode.S) || Input.GetKey(KeyCode.D) || Input.GetAxis("Horizontal") > deadZone || Input.GetAxis("Horizontal") < -deadZone) { playerAnimationState = animationState.Jogging; if (Input.GetKey(KeyCode.LeftShift)) { playerAnimationState = animationState.Running; } else if (Input.GetKey(KeyCode.Z)) { playerAnimationState = animationState.Walking; } } else { playerAnimationState = animationState.Idling; } //check for aiming if (Input.GetMouseButton(1)) { isAiming = true; playerAnimationState = animationState.Aiming; //if we have chosen to fire during aiming if (Input.GetMouseButtonDown(0)) { firedBow = true; } else { firedBow = false; } } //on frame aiming has stopped if (Input.GetMouseButtonUp(1)) { isAiming = false; } //rolling action if (Input.GetKey(KeyCode.R)) { isAnimationLocked = true; playerAnimationState = animationState.Rolling; StartCoroutine(WaitForAnimation("DS roll fwd")); //wait for animation, and send roll movement command to Motor StartCoroutine(WaitXSeconds(1f)); } //L1 attack action, with left click if (Input.GetKeyDown(KeyCode.Mouse0)) { switch (currentAttackChain) { case 0: isAnimationLocked = true; playerAnimationState = animationState.L1Attack; currentAttackChain += 1; StartCoroutine(WaitXSeconds(1f)); break; case 1: isAnimationLocked = true; playerAnimationState = animationState.L1AttackC2; currentAttackChain += 1; StartCoroutine(WaitXSeconds(1f)); break; case 2: isAnimationLocked = true; playerAnimationState = animationState.L1Attack; currentAttackChain += 1; StartCoroutine(WaitXSeconds(1f)); break; default: break; } } //Equip item action if (Input.GetKeyDown(KeyCode.Y)) { PlayerObject.Instance.equipPlayer("Recurve Bow"); PlayerObject.Instance.equipPlayer("Katana"); } }
//Load the next title into the correct title box private void DisplayNextTitle(animationState state) { Storyboard titleSet1AnimationStoryboard = (Storyboard)FindResource("titleSet1Animation"); Storyboard titleSet2AnimationStoryboard = (Storyboard)FindResource("titleSet2Animation"); Storyboard titleSet1OverlapAnimationStoryboard = (Storyboard)FindResource("titleSet1OverlapAnimation"); Storyboard titleSet2OverlapAnimationStoryboard = (Storyboard)FindResource("titleSet2OverlapAnimation"); Storyboard disclaimerTextAnimationStoryboard = (Storyboard)FindResource("disclaimerTextAnimation"); Storyboard initialDelayAnimationStoryboard = (Storyboard)FindResource("initialDelayAnimation"); Storyboard windowFadeOutAnimationStoryboard = (Storyboard)FindResource("windowFadeOutAnimation"); Storyboard overlap1AnimationStoryboard = (Storyboard)FindResource("overlap1Animation"); Storyboard overlap2AnimationStoryboard = (Storyboard)FindResource("overlap2Animation"); if (_titles.Count > _currentTitle) //There are more titles to display { switch (state) { case animationState.windowLoaded: { initialDelayAnimationStoryboard.Begin(this); break; } case animationState.initalDelayCompleted: { nameBox1.ItemsSource = _titles[_currentTitle].NamesCollection; if (_titles[_currentTitle].AnimationType == AnimationType.DistinctNoTitle || _titles[_currentTitle].AnimationType == AnimationType.OverlapNoTitle) { titleBox1.Visibility = Visibility.Collapsed; titleSet1OverlapAnimationStoryboard.Begin(this); //Use the overlap animation to accelerate the display of the name in a set without a title } else { titleBox1.Visibility = Visibility.Visible; titleBox1.Text = _titles[_currentTitle].Title; titleSet1AnimationStoryboard.Begin(this); } overlap1AnimationStoryboard.Begin(this); _currentTitle++; break; } case animationState.title1Completed: { if (_titles[_currentTitle].AnimationType != AnimationType.Overlap && _titles[_currentTitle].AnimationType != AnimationType.OverlapNoTitle) //Overlapped Animations would already be running at this point { nameBox1.ItemsSource = _titles[_currentTitle].NamesCollection; if (_titles[_currentTitle].AnimationType == AnimationType.DistinctNoTitle) { titleBox1.Visibility = Visibility.Collapsed; titleSet1OverlapAnimationStoryboard.Begin(this); //Use the overlap animation to accelerate the display of the name in a set without a title (not marked as such so it doesn't invalidate the above) } else { titleBox1.Visibility = Visibility.Visible; titleBox1.Text = _titles[_currentTitle].Title; titleSet1AnimationStoryboard.Begin(this); } overlap1AnimationStoryboard.Begin(this); } _currentTitle++; break; } case animationState.title2Completed: { if (_titles[_currentTitle].AnimationType != AnimationType.Overlap && _titles[_currentTitle].AnimationType != AnimationType.OverlapNoTitle) //Overlapped Animations would already be running at this point { nameBox2.ItemsSource = _titles[_currentTitle].NamesCollection; if (_titles[_currentTitle].AnimationType == AnimationType.DistinctNoTitle) { titleBox2.Visibility = Visibility.Collapsed; titleSet2OverlapAnimationStoryboard.Begin(this); //Use the overlap animation to accelerate the display of the name in a set without a title (not marked as such so it doesn't invalidate the above) } else { titleBox2.Visibility = Visibility.Visible; titleBox2.Text = _titles[_currentTitle].Title; titleSet2AnimationStoryboard.Begin(this); } overlap2AnimationStoryboard.Begin(this); } _currentTitle++; break; } case animationState.overlap1Completed: { //The overlap animation runs every time and signals when an overlapped title should begin. if (_titles[_currentTitle].AnimationType == AnimationType.Overlap || _titles[_currentTitle].AnimationType == AnimationType.OverlapNoTitle) { //We need to overlap the next animation, start it now: //Overlapping 1 with 2: nameBox2.ItemsSource = _titles[_currentTitle].NamesCollection; if (_titles[_currentTitle].AnimationType == AnimationType.OverlapNoTitle) { titleBox2.Visibility = Visibility.Collapsed; } else { titleBox2.Visibility = Visibility.Visible; titleBox2.Text = _titles[_currentTitle].Title; } titleSet2OverlapAnimationStoryboard.Begin(this); overlap2AnimationStoryboard.Begin(this); } else //Don't overlap; the regular completed handlers will re-fill themselves then run again { } break; } case animationState.overlap2Completed: { //The overlap animation runs every time and signals when an overlapped title should begin. if (_titles[_currentTitle].AnimationType == AnimationType.Overlap || _titles[_currentTitle].AnimationType == AnimationType.OverlapNoTitle) { //We need to overlap the next animation, start it now: //Overlapping 2 with 1: nameBox1.ItemsSource = _titles[_currentTitle].NamesCollection; if (_titles[_currentTitle].AnimationType == AnimationType.OverlapNoTitle) { titleBox1.Visibility = Visibility.Collapsed; } else { titleBox1.Visibility = Visibility.Visible; titleBox1.Text = _titles[_currentTitle].Title; } titleSet1OverlapAnimationStoryboard.Begin(this); overlap1AnimationStoryboard.Begin(this); } else //Don't overlap; the regular completed handlers will re-fill themselves then run again { } break; } } } else if (state != animationState.overlap1Completed && state != animationState.overlap2Completed) //No more titles; display the ending text { switch (state) { case animationState.disclaimerTextCompleted: { windowFadeOutAnimationStoryboard.Begin(this); break; } default: { disclaimerTextAnimationStoryboard.Begin(this); break; } } } }
void Update() { //run left if (running == true && grounded == true && currentFacing == facing.Left && currentAnimation != animationState.WalkLeft) { currentAnimation = animationState.WalkLeft; animator.SetInteger(animState, 1); transform.localScale = new Vector3(-1, 1, 1); } //run right if (running == true && grounded == true && currentFacing == facing.Right && currentAnimation != animationState.WalkRight) { currentAnimation = animationState.WalkRight; animator.SetInteger(animState, 1); transform.localScale = new Vector3(1, 1, 1); } //stand left if (running == false && grounded == true && currentFacing == facing.Left && currentAnimation != animationState.StandLeft) { currentAnimation = animationState.StandLeft; animator.SetInteger(animState, 0); transform.localScale = new Vector3(-1, 1, 1); } //stand right if (running == false && grounded == true && currentFacing == facing.Right && currentAnimation != animationState.StandRight) { currentAnimation = animationState.StandRight; animator.SetInteger(animState, 0); transform.localScale = new Vector3(1, 1, 1); } //fall left if (grounded == false && currentFacing == facing.Left && currentAnimation != animationState.FallLeft) { currentAnimation = animationState.FallLeft; animator.SetInteger(animState, 2); transform.localScale = new Vector3(-1, 1, 1); } //fall right if (grounded == false && currentFacing == facing.Right && currentAnimation != animationState.FallRight) { currentAnimation = animationState.FallRight; animator.SetInteger(animState, 2); transform.localScale = new Vector3(1, 1, 1); } }
// Update is called once per frame void FixedUpdate() { if (anilock > -1) { anilock--; } if (anilock < 0) { basicAttack.SetActive(false); a = animationState.still; } state = GamePad.GetState(controllerNum); if (Mathf.Abs(prePos.y - transform.position.y) > 0.001f) { falling = true; } else { falling = false; } gameObject.GetComponent <IndAnim> ().current = immortal.animations[index].getWalk(); RaycastHit2D groundCheck = Physics2D.Raycast(transform.position, Vector2.down, .35f); RB.velocity = new Vector2(playerSpeed * state.ThumbSticks.Left.X, RB.velocity.y); if (state.Buttons.A == ButtonState.Pressed && prestate.Buttons.A == ButtonState.Released && !falling) { RB.velocity += new Vector2(0, jumpheight); } if (state.ThumbSticks.Left.X < 0) { transform.rotation = Quaternion.Euler(180, 0, 180); if (anilock < 0) { a = animationState.walk; } } else if (state.ThumbSticks.Left.X > 0) { transform.rotation = Quaternion.Euler(0, 0, 0); if (anilock < 0) { a = animationState.walk; } } if (falling && anilock < 0) { a = animationState.falling; } if (script.abilityAUpdate(state, prestate)) { a = animationState.a; } if (script.abilityBUpdate(state, prestate)) { a = animationState.b; } if (script.abilityXUpdate(state, prestate)) { a = animationState.x; } if (script.abilityYUpdate(state, prestate)) { a = animationState.y; } script.abilityUpdate(state, prestate); switch (a) { case animationState.spin: gameObject.GetComponent <IndAnim> ().current = immortal.animations[index].getSpin(); break; case animationState.still: gameObject.GetComponent <IndAnim> ().current = immortal.animations[index].getIdle(); break; case animationState.walk: gameObject.GetComponent <IndAnim> ().current = immortal.animations[index].getWalk(); break; case animationState.a: gameObject.GetComponent <IndAnim> ().current = immortal.animations [index].getAbilityA(); if (anilock < 0) { anilock = immortal.animations [index].getAbilityA().Length *gameObject.GetComponent <IndAnim> ().aniSpeed; gameObject.GetComponent <IndAnim> ().frame = 0; } break; case animationState.b: gameObject.GetComponent <IndAnim> ().current = immortal.animations [index].getAbilityB(); if (anilock < 0) { anilock = immortal.animations [index].getAbilityB().Length *gameObject.GetComponent <IndAnim> ().aniSpeed; gameObject.GetComponent <IndAnim> ().frame = 0; } break; case animationState.x: basicAttack.SetActive(true); gameObject.GetComponent <IndAnim> ().current = immortal.animations [index].getAbilityX(); if (anilock < 0) { anilock = immortal.animations [index].getAbilityX().Length *gameObject.GetComponent <IndAnim> ().aniSpeed; gameObject.GetComponent <IndAnim> ().frame = 0; } break; case animationState.y: gameObject.GetComponent <IndAnim> ().current = immortal.animations [index].getAbilityY(); if (anilock < 0) { anilock = immortal.animations [index].getAbilityY().Length *gameObject.GetComponent <IndAnim> ().aniSpeed; gameObject.GetComponent <IndAnim> ().frame = 0; } break; } prestate = state; prePos = transform.position; attackDir.transform.rotation = PointerRotation(state.ThumbSticks.Left); }
public void reset() { state = animationState.IDLE; prevState = state; justChangedState = false; }
void FixedUpdate() { if (turnEnded) { Vector3 dir = TilemapHandler.getTile(targetTile).transform.position - (transform.position - Vector3.up - new Vector3(0.5f, 0.1f)); Vector3 movement = Vector3.zero; if ((dir.x * Vector3.right).sqrMagnitude > 0.02f) { movement = Vector3.right * (dir.x < 0 ? -1 : 1) * 0.1f; anim.SetBool(dir.x < 0 ? "Left" : "Right", true); if (state != animationState.LeftRight) { anim.SetTrigger("Reset"); state = animationState.LeftRight; } } else if ((dir.y * Vector3.up).sqrMagnitude > 0.02f) { movement = Vector3.up * (dir.y < 0 ? -1 : 1) * 0.1f; anim.SetBool(dir.y < 0 ? "Down" : "Up", true); anim.SetBool("Left", false); anim.SetBool("Right", false); if (state != animationState.UpDown) { anim.SetTrigger("Reset"); state = animationState.UpDown; } } else if (kicksBall) { kicksBall = false; GameObject.Find("Ball").GetComponent <BallController>().kick(); } else { if (hasBall) { GameObject.Find("Ball").GetComponent <BallController>().updatePosition(); } turnEnded = false; anim.SetTrigger("Reset"); anim.SetBool("Left", false); anim.SetBool("Right", false); anim.SetBool("Up", false); anim.SetBool("Down", false); } transform.position += movement; if (hasBall) { GameObject.Find("Ball").transform.position += movement; } else if (TilemapHandler.getTile(TilemapHandler.getTileAtPosition(transform.position - Vector3.up * 0.5f)).getHasBall()) { hasBall = true; TilemapHandler.getTile(TilemapHandler.getTileAtPosition(transform.position)).GetComponent <TileHandler>().setHasBall(false); TilemapHandler.getTile(tilePosition).GetComponent <TileHandler>().setHasBall(true); } } }
//handles players inputs for actions, things like moving, attacking, etc. see above each keyCode check for more info void HandleActionInput() { //if we are anim locked, leave this function. no Actions can happen until we are no longer locked if (isAnimationLocked == true) { return; } //default state, only modified if some other action happens playerAnimationState = animationState.Idling; //movement checks for the animators, always check these first then other action inputs. if (isMoving) { playerAnimationState = animationState.Jogging; if (InputHandler.Instance.checkAction(InputHandler.actions.RUN)) { //cant run if we are sneaking, so check that and proceed accordingly if (isSneaking == false) { isRunning = true; playerAnimationState = animationState.Running; } } else if (Input.GetKey(KeyCode.Z)) { isWalking = true; } else { isWalking = false; isRunning = false; } } else { playerAnimationState = animationState.Idling; } //check for crouching if (Input.GetKeyDown(KeyCode.LeftControl)) { //check and inverse our sneaking state. if (isSneaking == false) { isSneaking = true; playerAnimationState = animationState.Sneaking; } else { isSneaking = false; } //set our Animation state AnimateBodyParts.Instance.setSneakState(isSneaking); } //continuation of crouch, but need to run every frame, LERP our way to the positon if (PlayerCharacterController.Instance.isSneaking) { cameraAnchorPoint.localPosition = Vector3.Lerp(cameraAnchorPoint.localPosition, crouchCamOffset, smoothSpeed * Time.deltaTime); } else { cameraAnchorPoint.localPosition = Vector3.Lerp(cameraAnchorPoint.localPosition, standCamOffset, smoothSpeed * Time.deltaTime); } //check for aiming if (InputHandler.Instance.checkAction(InputHandler.actions.AIM)) { isAiming = true; } else { isAiming = false; } //player roll check if (InputHandler.Instance.checkAction(InputHandler.actions.ROLL)) { //run the rolling coroutine, set our animationLock isAnimationLocked = true; StartCoroutine(RollAction(1f)); } //light attack action if (InputHandler.Instance.checkAction(InputHandler.actions.LIGHTATTACK)) { //if not locked, start R1 chain if (!isAttackLocked) { StartCoroutine(playerAttack("R1", .5f)); } //run the FireWeapon coroutine, if we arent currently in a isFiring state. or reloading //if(!isFiring && !isReloading) //StartCoroutine(FireWeapon(.3f)); } //heavy attack action if (InputHandler.Instance.checkAction(InputHandler.actions.HEAVYATTACK)) { //if not locked, start R2 chain if (!isAttackLocked) { StartCoroutine(playerAttack("R2", 1f)); } } //Flashlight boolean check. if (Input.GetKeyDown(KeyCode.F)) { //negate whatever we were set to, and send to the flashlight controller flashLightOn = !flashLightOn; flashlight.setFlashlight(flashLightOn); } //TODO: Use item command if (InputHandler.Instance.checkAction(InputHandler.actions.USEITEM)) { } //change camera state, If 1Person -> 3Person, else 3P -> 1P if (InputHandler.Instance.checkAction(InputHandler.actions.CHANGECAM)) { changeCameraState(); } //switch player stance (2h vs 1 hand) if (InputHandler.Instance.checkAction(InputHandler.actions.SWITCHSTANCE)) { is2h = !is2h; } }
void FixedUpdate() { if (anilock >= 0) { anilock--; } cur = gameObject.transform.position; an = animationState.still; if (cur.x - pre.x > 0) { transform.rotation = Quaternion.Euler(180, 0, 180); an = animationState.walk; } else if (cur.x - pre.x < 0) { transform.rotation = Quaternion.Euler(0, 0, 0); an = animationState.walk; } if (cool < 0 && moveTime > 0) { cool = (int)((Random.value * 100) / 2) + 60; GetComponent <Rigidbody2D> ().velocity = new Vector2(((Random.value / 2) + .5f) * 14 * dir, 0); dir *= -1; } else { cool--; } moveTime--; if (moveTime == 0) { an = animationState.x; GetComponent <Rigidbody2D> ().velocity = new Vector2(0, 0); } if (moveTime < -2 * 60) { moveTime = 6 * 60; } if (anilock < 0) { switch (an) { case animationState.still: attack.SetActive(false); gameObject.GetComponent <IndAnim> ().current = immortal.animations [4].getIdle(); break; case animationState.walk: attack.SetActive(false); gameObject.GetComponent <IndAnim> ().current = immortal.animations [4].getWalk(); break; case animationState.x: gameObject.GetComponent <IndAnim> ().current = immortal.animations [4].getAbilityX(); attack.SetActive(true); anilock = immortal.animations [4].getAbilityX().Length *gameObject.GetComponent <IndAnim> ().aniSpeed; break; } } pre = cur; }
//handles players inputs for actions, things like moving, attacking, etc. see above each keyCode check for more info void HandleActionInput() { //if we are anim locked, leave this function. no Actions can happen until we are no longer locked if (isAnimationLocked == true) { return; } //default state, only modified if some other action happens playerAnimationState = animationState.Idling; //movement checks for the animators, always check these first then other action inputs. if (Input.GetKey(KeyCode.W) || Input.GetKey(KeyCode.A) || Input.GetKey(KeyCode.S) || Input.GetKey(KeyCode.D)) { playerAnimationState = animationState.Jogging; if (Input.GetKey(KeyCode.LeftShift)) { //cant run if we are sneaking, so check that and proceed accordingly if (isSneaking == false) { isRunning = true; playerAnimationState = animationState.Running; } } else if (Input.GetKey(KeyCode.Z)) { isWalking = true; } else { isWalking = false; isRunning = false; } } else { playerAnimationState = animationState.Idling; } //check for crouching if (Input.GetKeyDown(KeyCode.LeftControl)) { //check and inverse our sneaking state. if (isSneaking == false) { isSneaking = true; playerAnimationState = animationState.Sneaking; } else { isSneaking = false; } //set our Animation state AnimateBodyParts.Instance.setSneakState(isSneaking); } //continuation of crouch, but need to run every frame, LERP our way to the positon if (PlayerCharacterController.Instance.isSneaking) { cameraAnchorPoint.localPosition = Vector3.Lerp(cameraAnchorPoint.localPosition, crouchCamOffset, smoothSpeed * Time.deltaTime); } else { cameraAnchorPoint.localPosition = Vector3.Lerp(cameraAnchorPoint.localPosition, standCamOffset, smoothSpeed * Time.deltaTime); } //check for aiming if (Input.GetMouseButton(1)) { isAiming = true; } //on frame aiming has stopped if (Input.GetMouseButtonUp(1)) { isAiming = false; } //reloading action if (Input.GetKey(KeyCode.R)) { //if were are not currently reloading, do not use negation here, because we send off coroutines, hard checks necessary if (!isReloading) { Instance.isReloading = true; //send off animation. AnimateArms.Instance.setReloading(true); AnimateWeapon.Instance.setReloading(true); //wait for Animation to play. based on weapon being handled. StartCoroutine(WaitXSecondsForReload(4.25f)); } } //Weapon fire action, with left click if (Input.GetKeyDown(KeyCode.Mouse0)) { //run the FireWeapon coroutine, if we arent currently in a isFiring state. or reloading if (!isFiring && !isReloading) { StartCoroutine(FireWeapon(.3f)); } } //Flashlight boolean check. if (Input.GetKeyDown(KeyCode.F)) { //negate whatever we were set to, and send to the flashlight controller flashLightOn = !flashLightOn; flashlight.setFlashlight(flashLightOn); } //OPEN KEY, E command if (Input.GetKey(KeyCode.E)) { } //change camera state, If 1Person -> 3Person, else 3P -> 1P if (Input.GetKeyDown(KeyCode.U)) { changeCameraState(); } }