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 Hyperion · Jan 04, 2013 at 11:26 PM · javascriptmecanimparametersanimationstate

Javascript controlling Mecanim?

Hi everyone,

My other problem was solved, but for some reason, one of my models is going into the ground when following my Player character. He has a collider, properly adjusted and all. I can't figure out the problem.

Here's my script:

 var Victim: Transform;         //target of robot
 var damp=1.0;                 //the speed at which robot turns
 var FireballPrefab:Transform;//the prefab for the projectile
 var savedTime=0;             //time since shooting
 var Tdist:float;              // distance between robot and Victim
 var moveSpeed=15;             //moving speed
 
 
 function Update()
 {
     //Initializing the animator component
     var Mek: Animator = GetComponent(Animator);
     
     //Variables for Shooting
     var seconds: int=Time.time;
     var oddeven=(seconds%2);            //seconds will make the oddeven  true or false
     
     //I have 2 parameters right now: Speed and Shooting
     if (Mek.GetBool("Shooting"))
     {
         Mek.SetFloat("Speed",0);
     }
  
     //finding dist
     if (Victim)
     {
         var Tdist = Vector3.Distance(Victim.position, transform.position);
         Mek.SetFloat("Tdist",Tdist);
     }
     
 
     //In range of Victim
     if(Tdist<100)
     {
         //looking at Victim
         var rotate = Quaternion.LookRotation(Victim.position-transform.position);
         transform.rotation=Quaternion.Slerp(transform.rotation,rotate,Time.deltaTime*damp);
     }
     //moving towards Victim
     if (Tdist>20 && Tdist<=50)
     {
         transform.Translate(Vector3.forward *moveSpeed* Time.deltaTime); //move forward
         Mek.SetFloat("Speed",moveSpeed); //setting Speed parameter
         Mek.SetBool("Shooting",false);     //shoot animation off
     }
     
     if (Tdist<=20)
     {
         Mek.SetFloat("Speed",0);        //Stop movement animation
         Mek.SetBool("Shooting",true);   //Start shooting animation
     }
     
     if (oddeven && Mek.GetBool("Shooting"))
     {    
         Mek.SetFloat("Speed",0);
         Shoot(seconds);                    //if oddeven is true and distance is <= than 20, call shoot function
     }
 }
     
 //Shooting Victim
 function Shoot(seconds)
 {
     
     if (seconds != savedTime)
     {
         var Fireball= Instantiate(FireballPrefab,transform.Find("TurretPoint").transform.position,Quaternion.identity);
     
         Fireball.rigidbody.AddForce(transform.forward*5000);
     
         savedTime=seconds;
     }
 
     
 }//End of Shooting function

  
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 Hyperion · Jan 24, 2013 at 10:02 PM

Hi everyone, I have fixed everything. No need for help with this question, but can you please look at my other question regarding Root Motion (the question is the Final Barrier of Mecanim)?

Comment
Add comment · Show 3 · 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 nicknasti · Jun 11, 2013 at 03:26 AM 0
Share

Are you going to tell us how you solved the going into the ground problem?

Thanks

avatar image Hyperion · Jun 11, 2013 at 07:14 PM 0
Share

Oh, wow, this is a pretty old question. I have accomplished so much since then. Hmmmm..... Let me see if I can remember how I did that....

I believe there might've been 2 things wrong, but one of the solutions was to increase height of collider to match the position of the feet. If you need something more specific, please ask a more specific question with details and all. Hope this helps.

avatar image Fekete · Dec 27, 2013 at 12:01 PM 0
Share

Thats why i always document everything...

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

10 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

Related Questions

accessing animation states from animator in javascript 0 Answers

Altered Mecanim parameters reset the current state back to the default state. 0 Answers

How can I use 1 key instead of two for toggling animation ? 2 Answers

Changing animation when moving horizontally without flipping sprite 0 Answers

How do I create a function that accepts EITHER vector3 OR three floats? 1 Answer


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