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 /
This post has been wikified, any user with enough reputation can edit it.
avatar image
0
Question by eaglemaster7 · Nov 30, 2012 at 07:59 AM · animationmecanimscriptingbasicsparameters

learn to scripting parameter in Mecanim

I am beginer in unity scripting, I just learn new mecanim system..

I have a 3 animations : walk stright, left and the right that is ready blend in mecanim

and I am using "directiions" and "speed" parameter to control it, (-1 for right, 0 for stright and 1 for left),

so I need my character to follow other agent or going to destination object, but I can't figure out how to script those parameter in order to make my avatar facing my stright to destination object.

thank you,

any help would be appreciated

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
2
Best Answer Wiki

Answer by Hyperion · Jan 06, 2013 at 01:54 AM

Everything in Unity-Javascript.

First, you have to make the character turn towards the object.

//looking at Target

         var rotate = Quaternion.LookRotation(Target.position-transform.position);
         transform.rotation=Quaternion.Slerp(transform.rotation,rotate,Time.deltaTime*damp);

Remember to declare the variable Target as Transform. This code simply turns the user towards target.

Then, make the character move towards target. I made a variable moveSpeed. Do not do it this way if your walking animation has Root Motion. Just set the speed parameter (explained at end of answer)

 transform.Translate(Vector3.forward *moveSpeed* Time.deltaTime); //move forward

If you also want to set parameter "Speed", declare a variable at the start of the Update function (whatever you want to call it) like this:

 //Initializing the animator component
     var YourAnimatorName: Animator = GetComponent(Animator);

Then, you can do

YourAnimatorName.SetFloat("Speed",YourSpeed);

Set float is only for speed, if it's a boolean, do SetBool, and so on. Put this where you get your Character to move.

Hope this helps,

Hyperion

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 Hyperion · Jun 11, 2013 at 07:30 PM 1
Share

If this answer was helpful, could you please accept it and vote it up? Thanks. That way I can provide more help in the future.

avatar image Mahesh4Unity · Feb 26, 2014 at 08:47 AM 0
Share

@Hyperion i'm getting error like "Parameter 'TestInput' does not exist", have you any idea what i'm doing wrong?

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

13 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

Related Questions

Random float parameter for idle animations 1 Answer

unity freezes when running sprinting animation 0 Answers

Changing variable value from Mecanim? 2 Answers

Animation will not Return to Proper State 2 Answers

how to set mecanim parameters for an ai? 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