Wayback Machinekoobas.hobune.stream
May JUN Jul
Previous capture 12 Next capture
2021 2022 2023
1 capture
12 Jun 22 - 12 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 /
  • Help Room /
avatar image
0
Question by PegeonOne · Apr 25, 2020 at 11:09 AM · animatoranimator controller3rd person controlleranimation script

Would like to know if I doing well the animation transition?

I learning animation transition with blend tree and Game Object movement system with that animation. My friend create a 3D model and few animation in blender. I wrote scripts for movement system and camera follow. It's working good enough as you can see on video https://www.youtube.com/watch?v=oy_IkfvZJKQ. However, I have animation that roll drone right and left, in my idea, drone should call roll animation and after call idle after roll done, that when i push "A" or "D" my Game Object turn left or right with roll and after moving as idle. I created variable that save a Vector3.Dot function with vector of drone and vector of camera, that allow me detect drone turning, but I think I made crazy things in my animator

alt text

alt text

     //variable initialization
     public float InputX;
     public float InputZ;
     public Vector3 desiredMoveDirection;
     public bool bloclRotationPlayer;
     public float speed = 12f;
     public float desiredRotationSpeed = 10f;
     public CharacterController controller;
     Vector3 velocity;
     public float allowPlayerRotation;
     public Animator anim;
     public Camera cam;
     public float gravity = -9.6f;
     public float verticalVel;
     private Vector3 moveVector;
     public Transform groundCheck;
     public float dist = 0.4f;
     public LayerMask groundMask;
     public float jumpH = 60f;
     Vector3 mVelocity;
     Vector3 droneRotation;
     bool isGrounded;
     public float movingSpeed = 20f;
     public bool CheckAnimFalling = false;
     public Vector3 objPos;
     CameraLook CameraLook;
     public float scalarMultForw;
 
     Vector3 moveDir;
 
     private void Start()
     {
         anim = GetComponent<Animator>();
         cam = Camera.main;
         controller = this.GetComponent<CharacterController>();
     }
     void Update()
     {
         //get some input
         InputX = Input.GetAxis("Horizontal");
         InputZ = Input.GetAxis("Vertical");
         //save Inputs in variables
         moveDir = new Vector3(InputX, 0 , InputZ);
         
         
         //define obj Position
         objPos = transform.forward;
         //Vector3.Dot with camera vector and drone vector
         scalarMultForw = Mathf.Round(Vector3.Dot(Camera.main.transform.right, objPos.normalized) * 100) / 100;
         //calling method that define the magnitude
         InputMagnitude();
         //jump staff
         if (Input.GetKey(KeyCode.Space))
         {
             verticalVel = Mathf.Sqrt(jumpH * -2f * gravity);
         }
 
         isGrounded = controller.isGrounded;
         if (isGrounded)
         {
             verticalVel -= 0;
             CheckAnimFalling = true;
         }
         else
         {
             verticalVel -= 2;
             CheckAnimFalling = false;
         }
        
         //move controller via jump or falling
         moveVector = new Vector3(0, verticalVel * Time.deltaTime, 0);
         controller.Move(moveVector);
          
     }
     void PlayerMoveAndRotation()
     {
         //method for define drone moving vector 
         var camera = Camera.main;
         var forward = cam.transform.forward;
         var right = cam.transform.right;
 
         forward.y = 0f;
         right.y = 0f;
 
         forward.Normalize();
         right.Normalize();
         
         
         desiredMoveDirection = forward * InputZ + right * InputX;
         Vector3 moveDir = desiredMoveDirection.normalized * movingSpeed * Time.deltaTime;
         controller.Move(moveDir * Time.deltaTime * 100f);
         
         //rotate Drone to direction if I move it
         if (bloclRotationPlayer == false)
         {
             transform.rotation = Quaternion.Slerp(transform.rotation, Quaternion.LookRotation(desiredMoveDirection),desiredRotationSpeed * Time.deltaTime * 0.2f);
         }
     }
     void InputMagnitude()
     {
         //method that control blend tree in the animator
         anim.SetFloat("InputZ", InputZ, 0.0f, Time.deltaTime * 2f);
         anim.SetFloat("InputX", InputX, 0.0f, Time.deltaTime * 2f);
         
         //checking if we stay or moving 
         speed = new Vector2(InputX, InputZ).sqrMagnitude;
 
         if (speed > allowPlayerRotation)
         {
             anim.SetFloat("InputMagnitude",speed,0.0f, Time.deltaTime);
             PlayerMoveAndRotation();
             anim.SetFloat("TurnCheck", scalarMultForw, 0.0f, Time.deltaTime);
         }
         else if(speed < allowPlayerRotation)
         {
             
             anim.SetFloat("InputMagnitude", speed, 0.0f, Time.deltaTime);
   
         }
         
 
     }

I guess I'm crazy, and make it wrong, can you help and give advise how work with animation, blend tree, transition correctly. How make create transition that Drone firstly roll to side and after that move as idle animation? If you need more material, just say

myplatformer-samplescene-pc-mac-linux-standalone-u.png (327.2 kB)
myplatformer-samplescene-pc-mac-linux-standalone-u.png (316.6 kB)
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
Best Answer

Answer by Eudaimonium · Apr 25, 2020 at 11:23 AM

You are not using the animator correctly. Blend trees are a tool for another purpose. A good example is variable movement speed of the player.

Let's say you have two animations for your player - running, and sprinting. But during gameplay, your player can move at any arbitrary speed between those two speeds. In that case, blend tree will kind of "make up" what animation between the two values might look like for any given speed between those two.

What you are trying to do is simple state transitions between any two well defined, and known states. This is what your normal animator does already. You need to simply set up your animation clips as states and call them from code (I find calling state names from code is much cleaner than using numerous parameters).

An example of how I would do you setup: [Roll Left] - > [Idle] [Roll Right] -> [Idle] (Note no transitions go INTO rolls).

Then, from code, simply call anim.Crossfade(string, float), where string is your state name as it appears in animator, and float is amount of seconds the crossfade will take (you probably want small values like 0f or 0.1f). More info: https://docs.unity3d.com/ScriptReference/Animator.CrossFade.html

Comment
Add comment · 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

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

236 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 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

Animator scripting error C# - Only WalkingRight Movement Animates 0 Answers

how to play clip animation via animator Onclick? 0 Answers

Animations Not Working when Pressing Certain Keys 1 Answer

How to fix animation delay in grid based game. 0 Answers

Continuous keydown in Animator 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