Wayback Machinekoobas.hobune.stream
May JUN Jul
Previous capture 13 Next capture
2021 2022 2023
1 capture
13 Jun 22 - 13 Jun 22
sparklines
Close Help
  • Products
  • Solutions
  • Made with Unity
  • Learning
  • Support & Services
  • Community
  • Asset Store
  • Get Unity

UNITY ACCOUNT

You need a Unity Account to shop in the Online and Asset Stores, participate in the Unity Community and manage your license portfolio. Login Create account
  • Blog
  • Forums
  • Answers
  • Evangelists
  • User Groups
  • Beta Program
  • Advisory Panel

Navigation

  • Home
  • Products
  • Solutions
  • Made with Unity
  • Learning
  • Support & Services
  • Community
    • Blog
    • Forums
    • Answers
    • Evangelists
    • User Groups
    • Beta Program
    • Advisory Panel

Unity account

You need a Unity Account to shop in the Online and Asset Stores, participate in the Unity Community and manage your license portfolio. Login Create account

Language

  • Chinese
  • Spanish
  • Japanese
  • Korean
  • Portuguese
  • Ask a question
  • Spaces
    • Default
    • Help Room
    • META
    • Moderators
    • Topics
    • Questions
    • Users
    • Badges
  • Home /
avatar image
0
Question by phitch516 · Sep 17, 2020 at 08:56 PM · inputanimator controller

blendtree animator float value does not return to zero after i have stopped giving input

I have a blend tree with idle, run forward, backward, and side to side animations. When i provide input, via left stick of gamepad , i move in all the given directions and animations play properly. Although when i release the stick and stop giving input, the player stops moving as expected, but the animation continues to play. In the editor, in the animator controller window, it shows the float value of the last input direction, ie. -1 or 1 on x axis or -1 or 1 on y axis , and i am using new input system, and i am using the example demo script that comes with input system 1.0.0 download. here is that script, thanks in advance for any help...

 using System.Collections;
  using UnityEngine;
  using UnityEngine.InputSystem;
  using UnityEngine.InputSystem.Interactions;
 
 // Use a separate PlayerInput component for setting up input.
 public class NewController_UsingPlayerInput : MonoBehaviour
 {
     public float moveSpeed;
     public float rotateSpeed;
     public float burstSpeed;
     public GameObject projectile;
     public GameObject bulletpoint;
 
     private Animator animator;
     private bool m_Charging;
     private Vector2 m_Rotation;
     private Vector2 m_Look;
     private Vector2 m_Move;
 
     public void OnMove(InputAction.CallbackContext context)
     {
         m_Move = context.ReadValue<Vector2>();
        
     }
 
     public void OnLook(InputAction.CallbackContext context)
     {
         m_Look = context.ReadValue<Vector2>();
     }
 
     public void OnFire(InputAction.CallbackContext context)
     {
         switch (context.phase)
         {
             case InputActionPhase.Performed:
                 if (context.interaction is SlowTapInteraction)
                 {
                     StartCoroutine(BurstFire((int)(context.duration * burstSpeed)));
                 }
                 else
                 {
                     Fire();
                 }
                 m_Charging = false;
                 break;
 
             case InputActionPhase.Started:
                 if (context.interaction is SlowTapInteraction)
                     m_Charging = true;
                 break;
 
             case InputActionPhase.Canceled:
                 m_Charging = false;
                 break;
         }
     }
 
     public void OnGUI()
     {
         if (m_Charging)
             GUI.Label(new Rect(100, 100, 200, 100), "Charging...");
     }
 
     public void Update()
     {
         // Update orientation first, then move. Otherwise move orientation will lag
         // behind by one frame.
         Look(m_Look);
         Move(m_Move);
     }
 
     private void Move(Vector2 direction)
     {
         if (direction.sqrMagnitude < 0.01)
             return;
         var scaledMoveSpeed = moveSpeed * Time.deltaTime;
         // For simplicity's sake, we just keep movement in a single plane here. Rotate
         // direction according to world Y rotation of player.
         var move = Quaternion.Euler(0, transform.eulerAngles.y, 0) * new Vector3(direction.x, 0, direction.y);
         transform.position += move * scaledMoveSpeed;
         animator = GetComponent<Animator>();
         if (direction.x > 0.1 || direction.x < -0.1 || direction.y > 0.1 || direction.y < -0.1)
         {
             animator.SetFloat("RunX", direction.x);
             animator.SetFloat("RunY", direction.y);
         }
         else
         {
             animator.SetFloat("RunX", 0);
             animator.SetFloat("RunY", 0);
         }
     }
     
 
     private void Look(Vector2 rotate)
     {
         if (rotate.sqrMagnitude < 0.01)
             return;
         var scaledRotateSpeed = rotateSpeed * Time.deltaTime;
         m_Rotation.y += rotate.x * scaledRotateSpeed;
         m_Rotation.x = Mathf.Clamp(m_Rotation.x - rotate.y * scaledRotateSpeed, -15, 15);
         transform.localEulerAngles = m_Rotation;
     }
 
     private IEnumerator BurstFire(int burstAmount)
     {
         for (var i = 0; i < burstAmount; ++i)
         {
             Fire();
             yield return new WaitForSeconds(0.1f);
         }
     }
 
     private void Fire()
     {
         var transform = this.transform;
         var newProjectile = Instantiate(projectile);
         newProjectile.transform.position = bulletpoint.transform.position + transform.forward * 0.5f;
       //  newProjectile.transform.position = transform.position + transform.up * 6.5f;
         newProjectile.transform.rotation = bulletpoint.transform.rotation;
         const int size = 1;
         newProjectile.transform.localScale *= size;
         newProjectile.GetComponent<Rigidbody>().mass = Mathf.Pow(size, 3);
         newProjectile.GetComponent<Rigidbody>().AddForce(transform.forward * 20f, ForceMode.Impulse);
         newProjectile.GetComponent<MeshRenderer>().material.SetColor("_Color", Color.red);
            // new Color(Random.value, Random.value, Random.value, 1.0f);
     }

Comment
Add comment
10 |3000 characters needed characters left characters exceeded
▼
  • Viewable by all users
  • Viewable by moderators
  • Viewable by moderators and the original poster
  • Advanced visibility
Viewable by all users

1 Reply

· Add your reply
  • Sort: 
avatar image
0

Answer by hexagonius · Sep 18, 2020 at 07:55 AM

This is the offending part:

  if (direction.sqrMagnitude < 0.01)
      return;

How should the animator ever be set to zero if you prevent it to happen?

Comment
Add comment · Show 1 · Share
10 |3000 characters needed characters left characters exceeded
▼
  • Viewable by all users
  • Viewable by moderators
  • Viewable by moderators and the original poster
  • Advanced visibility
Viewable by all users
avatar image phitch516 · Sep 18, 2020 at 02:39 PM 0
Share

thanks ,, ,, i didn't notice that, i copied the demo script that came with input system, it was originally meant for fps not a character, after a couple of months using unity , i thought i wouldn't still be getting hung up on simple stuff,, :)thanks again...

Your answer

Hint: You can notify a user about this post by typing @username

Up to 2 attachments (including images) can be used with a maximum of 524.3 kB each and 1.0 MB total.

Follow this Question

Answers Answers and Comments

167 People are following this question.

avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image

Related Questions

How is it possible to Lerp from a non initialized value to an initialized value? 1 Answer

How to prevent an animation from triggering more than on due to fast clicking? 2 Answers

C# animator bool 1 Answer

it may be easy but i did not know how to do the same - How can i modify toadd attack animation in predefined Animator of third person character in unity 0 Answers

Animation transition not recognized while holding multiple keys 0 Answers


Enterprise
Social Q&A

Social
Subscribe on YouTube social-youtube Follow on LinkedIn social-linkedin Follow on Twitter social-twitter Follow on Facebook social-facebook Follow on Instagram social-instagram

Footer

  • Purchase
    • Products
    • Subscription
    • Asset Store
    • Unity Gear
    • Resellers
  • Education
    • Students
    • Educators
    • Certification
    • Learn
    • Center of Excellence
  • Download
    • Unity
    • Beta Program
  • Unity Labs
    • Labs
    • Publications
  • Resources
    • Learn platform
    • Community
    • Documentation
    • Unity QA
    • FAQ
    • Services Status
    • Connect
  • About Unity
    • About Us
    • Blog
    • Events
    • Careers
    • Contact
    • Press
    • Partners
    • Affiliates
    • Security
Copyright © 2020 Unity Technologies
  • Legal
  • Privacy Policy
  • Cookies
  • Do Not Sell My Personal Information
  • Cookies Settings
"Unity", Unity logos, and other Unity trademarks are trademarks or registered trademarks of Unity Technologies or its affiliates in the U.S. and elsewhere (more info here). Other names or brands are trademarks of their respective owners.
  • Anonymous
  • Sign in
  • Create
  • Ask a question
  • Spaces
  • Default
  • Help Room
  • META
  • Moderators
  • Explore
  • Topics
  • Questions
  • Users
  • Badges