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 dragonlord119 · Apr 28, 2015 at 06:42 AM · c#animationunity 5parameters

Why aren't my parameters for animation not working?

I managed to get my enemy ai script up and working; he detects the player, follows him and shoots when in range. However, I am trying to add parameters to allow animations to play when the enemy has entered different states (attack, follow, e.t.c.) Here is my script with some commented out attempts at making the animations work.

 using UnityEngine;
 using System.Collections;
 
 public class EnemyAIScript : MonoBehaviour 
 {
 
     private Transform player;
     private float playerDistance;
     private float rotationDamping = 5f;
     public float attackRange = 10f;
     public float moveSpeed = 2f;
     public float startChaseRange = 20f;
     public static bool isPlayerAlive = true;
     public float fireRate = 5f;
     private float maxFire;
     private float nextFire;
     public Rigidbody BulletPrefab;
     public float BulletSpeed = 10;
     public Vector3 velocity;
     Animator animator;
     /*AudioSource droneSource;
     AudioClip [] droneSounds;
     AudioClip droneWalk;
     AudioClip droneFire;
     AudioClip droneRoll;
     AudioClip droneOpen;
     AudioClip droneClose;*/
 
     void Start ()
     {
         player = GameObject.Find ("Player").GetComponent <Transform> ();
         animator = GetComponent <Animator> ();
         /*droneSounds = GetComponents <AudioClip> ();
         for (int i = 0; i < droneSounds.Length; i++) 
         {
             if (droneSounds [i].name == "Fire")
             {
                 droneFire = droneSounds [i];
             }
             else if (droneSounds [i].name == "Walk")
             {
                 droneWalk = droneSounds [i];
             }
             else if (droneSounds [i].name == "Roll")
             {
                 droneRoll = droneSounds [i];
             }
             else if (droneSounds [i].name == "Open")
             {
                 droneOpen = droneSounds [i];
             }
             else if(droneSounds [i].name == "Close")
             {
                 droneClose = droneSounds [i];
             }
         }*/
     }
 
     void Update () 
     {
         if (isPlayerAlive) 
         {
             playerDistance = Vector3.Distance (player.position, transform.position);
             if (playerDistance < startChaseRange) 
             {
                 lookAtPlayer ();
             }
             if (playerDistance < startChaseRange) 
             {
                 if (playerDistance > attackRange) 
                 {
                     chase ();
                 }
                 else if (playerDistance < attackRange) 
                 {
                     attack ();
                 }
             }
         }
     }
     void lookAtPlayer ()
     {
         Quaternion rotation = Quaternion.LookRotation (player.position - transform.position);
         transform.rotation = Quaternion.Slerp (transform.rotation, rotation, Time.deltaTime * rotationDamping);
         float move = moveSpeed;
         animator.SetFloat ("Moving", move);
     }
 
     void chase ()
     {
         transform.Translate (Vector3.forward * moveSpeed * Time.deltaTime);
         /*animator.SetTrigger ("Hide");
         animator.SetBool ("Open", false);
         animator.SetBool ("Moving", false);
         animator.SetBool ("Rolling", true);*/
         //float move = moveSpeed;
         //animator.SetFloat ("Speed", move);
     }
 
     void attack ()
     {
         /*float stop = moveSpeed;
         animator.SetFloat ("Stop", stop);
         animator.SetBool ("Rolling", false);
         animator.SetBool ("Open", true);*/
         if (Time.time > nextFire) 
         {
             nextFire = Time.time + fireRate;
             Rigidbody instantiatedProjectile = Instantiate (BulletPrefab, GameObject.Find ("spawnPoint").transform.position,  Quaternion.identity) as Rigidbody;
             instantiatedProjectile.velocity = transform.TransformDirection (new Vector3 (0, 0, BulletSpeed));
             /*float shoot = attackRange;
             animator.SetFloat ("Shoot", shoot);*/
         }
     }
 }

The audio scripting is on the back burner for now. I'm interested to know why my parameters don't work when I use the animator controller in unity. I set up a parameter, whether a float, int, bool, or trigger, name it correctly to match the script. I then make a transition between two animations in the state machine. Yet when the enemy reaches these values, nothing happens.

For example, the enemy is a spider bot that rolls into a ball (and therefore not humanoid). The animations were made in blender by a friend of mine and are a little trickier to use than animations created in unity but I think I can handle it. The problem starts when he is in idle (just sitting in his ball form). When the player is within 20f of the robot, he moves towards the player. The animation for rolling is supposed to play, but it doesn't. The parameter for movement has been set up and added to the transition, values are fairly low (his move speed is currently 2f).

If anyone could help me or point me to a dedicated animation tutorial (preferably something outside of unity.com itself, those ten minute videos are informative but short.) I am also using unity 5, which may be the reason for it not working (the a.p.i.'s could be different, but for me who is fairly new to coding it is difficult to understand. Any and all help is 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

0 Replies

· Add your reply
  • Sort: 

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

2 People are following this question.

avatar image avatar image

Related Questions

How to open the door when I need 1 Answer

Animation Playing issues in Unity 5 with C# 1 Answer

Modifying script values using animations 0 Answers

Door animation bugs and stays open unity 3D 0 Answers

help me please dont understand problem with animation 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