Search Unity

  1. Welcome to the Unity Forums! Please take the time to read our Code of Conduct to familiarize yourself with the forum rules and how to post constructively.
  2. We have updated the language to the Editor Terms based on feedback from our employees and community. Learn more.
    Dismiss Notice
  3. Join us on November 16th, 2023, between 1 pm and 9 pm CET for Ask the Experts Online on Discord and on Unity Discussions.
    Dismiss Notice

Stopping movement of the player while shooting

Discussion in 'Getting Started' started by ElectricMonkey, Apr 10, 2015.

  1. ElectricMonkey

    ElectricMonkey

    Joined:
    Mar 10, 2015
    Posts:
    12
    Hey,

    I'm basing my game off the survival shooter tutorial and i'm trying to make it so the player does not move after pressing "Fire1" , but plays the animation and then continues walking.

    What would be the best way to approach this? Should I use a bool to check every frame if the player is not attacking(then play the standard animations and movement code), but if he is attacking, then only play the attack animation?

    (I'm using Mecanim btw)

    Thanks for any help.
     
  2. Ness

    Ness

    Joined:
    Oct 1, 2012
    Posts:
    182
    Try adding a transition from move animation state directly to shoot animation(triggered with the bool/trigger) then enable this condition whenever you press Fire1
     
  3. ElectricMonkey

    ElectricMonkey

    Joined:
    Mar 10, 2015
    Posts:
    12
    It's not an animation matter. I'm trying to make it so his movement code is disabled while he is pressing Fire1 or if he presses Fire1, leave a delay of a few seconds and then re-enable the movement code.
     
  4. Ness

    Ness

    Joined:
    Oct 1, 2012
    Posts:
    182
    Its difficult to understand 100% precisly what you want to achieve here.
    Another thought would be to use:

    Code (CSharp):
    1. If(animator.GetCurrentAnimatorStateInfo(0).IsName("nameOfStateHoldingFireAnimation"))
    2. {
    3. // disable movement code
    4. }
     
  5. Schneider21

    Schneider21

    Joined:
    Feb 6, 2014
    Posts:
    3,510
    Alternatively, consider updating your controller to check if they're firing before processing any movement input. If they are firing, skip that frame of movement input.

    If you actually want to freeze them in place while firing, you may have to alter the force applied to the controller, set its velocity to 0, or explicitly define its position (or a combination of these) depending on how your movement is actually handled.