Search Unity

Question Decrementing Input values - haaaalp

Discussion in 'Scripting' started by DrewofDonuts, Apr 29, 2021.

  1. DrewofDonuts

    DrewofDonuts

    Joined:
    Apr 23, 2020
    Posts:
    28
    [Resolved]

    I'm just a lowly fledgling mashing away until code sort of works, and to no surprise, I'm really struggling with the problem described below (Unity). If any of you superheroes would be so kind to help, I'd greatly appreciate it!

    Goal: In a top down view with a static camera, have a humanoid animation smoothly transition from a 2D Blend tree to a separate idle state.

    What works: Player uses mouse-aim and blends into the correct strafing animation based on its rotation & movement direction.

    What's wrong: When I stop moving, the player SNAPS into the idle position.

    Challenge: Decrementing the Input value 1 -> 0 . If I can make this work, the rest of the code should behave!

    If you'd like to go the extra step and see what (embarrassing) code I have, please PM me!
     
    Last edited: Apr 30, 2021
  2. Brathnann

    Brathnann

    Joined:
    Aug 12, 2014
    Posts:
    7,187
    I don't understand... How is decrementing the value a challenge?
     
  3. Kurt-Dekker

    Kurt-Dekker

    Joined:
    Mar 16, 2013
    Posts:
    38,686
    As Brath points out, decrementing does this: it goes from 1 to 0.

    If you mean to smoothly transition a quantity from 1 to 0, that takes a little more, and this is the generic pattern that I always use for ANY quantities that needs to be smoothly changed over time.

    Smoothing movement between discrete values:

    https://forum.unity.com/threads/beginner-need-help-with-smoothdamp.988959/#post-6430100

    The code: https://pastebin.com/ePnwWqnM
     
  4. WTF? Why would anyone do that? You need help, you need to share what you got so we can tell you where to change stuff so make it work.
     
    Brathnann likes this.
  5. DrewofDonuts

    DrewofDonuts

    Joined:
    Apr 23, 2020
    Posts:
    28
    Thanks for the responses guys! I did not use accurate terminology - Kurt identified it well. I wanted to smoothly transition a quantity from 1 to 0.

    Someone helped me out by teaching me the difference between Input.GetAxis and Input.GetRawAxis. So, now I'm passing a GetAxis value through, smoothing it a bit more, and passing that to my animator separate from the input that controls movement. Maybe not as optimized as interpolating from GetAxisRaw to GetAxis, but it'll do for now.

    My apologies for being unclear!
     
  6. DrewofDonuts

    DrewofDonuts

    Joined:
    Apr 23, 2020
    Posts:
    28
    I was hoping to spare everyone's time and simply isolate where I know the problem was. In most cases, I probably would share my code if the issue was more...nebulus.