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 /
avatar image
0
Question by GameC12 · Nov 06, 2016 at 10:12 PM · c#animationcrouching

Play Animation

I have a cube character. I have two animations, one that has him "crouch" and one that has him "stand". My character is setup is as show in the image. "Player" has the movement script and the rigidbody. "Graphics" has everything a normal cube does except the collider, and "collider" has the collider. "Camera" is the camera. "Animations" is an empty gameobject. "Animator" has an animator on it with my player animation controller on it. I have a c# script and i am trying to get my player to crouch. I want my player to crouch when I press left shift. The reason the animator is on a separate gameobject as my movement script is because my player won't move if the animator was on the same object. I would prefer if the crouching script would be included in my movement script, which is on the "Player" object. Please help.alt text

screen-shot-2016-11-06-at-41826-pm.png (7.7 kB)
Comment
Add comment · Show 1
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 frederik99 · Nov 06, 2016 at 10:55 PM 0
Share

what does your animation-state-machine look like?

2 Replies

· Add your reply
  • Sort: 
avatar image
0

Answer by GameC12 · Nov 07, 2016 at 07:41 AM

Not sure if you mean this but here is what i think you mean. I am still trying to learn all the terminology of game devs.alt text


screen-shot-2016-11-06-at-62102-pm.png (35.0 kB)
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 frederik99 · Nov 07, 2016 at 10:51 AM 0
Share

yes, that's the right one. Axtrainz already posted the solution. You can activate the "Crouch" and "Stand" parameters from every Script you like by calling

 animator.SetTrigger("Crouch");

Does it work for you?

avatar image
0

Answer by Axtrainz · Nov 06, 2016 at 11:30 PM

Assuming your Animator Parameter to trigger Crunch animation is bool crunch you can do this:

for general purpose we create an Animator field:

  public Animator anim;

then let's do a function for clear vision:

 public void Crunch_Me()
 {
          if (Input.GetKey(KeyCode.LeftShift))
         {
             if (anim != null)
             {
                 if (anim.GetBool("crunch") != true)
                     anim.SetBool("crunch", true);
                 else
                     anim.SetBool("crunch", false);
             }
         }// get key if
 }//function

You should call this function on:

FixedUpdate()

Comment
Add comment · Show 2 · 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 GameC12 · Nov 07, 2016 at 09:34 PM 0
Share

Sorry, but the script still isn't working. I copied exactly what Axtrainz said above, and called it in the fixed update function. I just don't have a parameter to trigger crouch as a bool. I have two triggers, Crouch and Stand, as shown in the image above.

avatar image Axtrainz GameC12 · Nov 07, 2016 at 09:38 PM 0
Share

Is the same thing, ins$$anonymous$$d of: anim.SetBool("crunch", true); you do: anim.SetTrigger("Crouch");

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

7 People are following this question.

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

Related Questions

Multiple Cars not working 1 Answer

Distribute terrain in zones 3 Answers

How to keep an animation attached to gameobject 0 Answers

How can i animate my Object? (bones available) 1 Answer

Timing particles for animation: Where to begin? 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