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 Numonic · Dec 12, 2016 at 10:00 PM · quests

Unity character rigging controls

Hi all I I have a question I have a character that walks runs and jumps with the standard wasd keys and jumps with spacebar. I would like him to transform when pressing a button and keep that animation and not move to another. I know its being canceled with the current code that I have and I can't seem to stop it. Here is my code

using UnityEngine; using System.Collections;

public class PlayerRobot : MonoBehaviour { //public GameObject player; public float speed = 3.0f; public float jumpSpeed = 150.0f;

 public float flightspeed = 10.0F;
 public float flightrotationSpeed = 100.0F;

 Rigidbody rigidbody;

 Animation anim;

 Animation animStop;

 bool isJetMode = false;

 bool isRobotMode = true;

 public float h = 0;

 public float v= 0;

 bool idleAnim = true;

 bool jumpAnim = true;

 bool runAnim = true;

 bool strafeleftAnim = true;

 bool straferightAnim = true;

 bool transformAnim = true;

 bool walkAnim = true;

 // Use this for initialization
 void Awake() 
 {
     rigidbody = GetComponent<Rigidbody> ();
     anim = GetComponent<Animation> ();


 }
     
 // Update is called once per frame
 void FixedUpdate () 
 {   
     RobotMove ();
     JetMode ();
     Jump ();
     VulcanAnim ();

     h = Input.GetAxis ("Horizontal");
     v = Input.GetAxis ("Vertical");
 }

 void Jump()
 {
     if (Input.GetButtonDown ("Jump")) 
     {
         GetComponent<Animation>().Play("jump");
         rigidbody.AddForce (Vector3.up * jumpSpeed);
     }
 }
 void JetMode()
 {   
     if (Input.GetMouseButtonDown (1)) 
     {
         GetComponent<Animation> ().Stop ("idle");
        anim.Play ("transform");

         rigidbody.AddForce (Vector3.up * jumpSpeed);
         rigidbody.mass = 1;
         rigidbody.drag = 0;
         rigidbody.useGravity = false;

         isJetMode = true;

          isRobotMode = false;

         print ("Gravity is turned off ");
     }

     if (Input.GetMouseButtonUp (1)) 
     { 
         GetComponent<Animation> ().Stop ("idle");
         anim.Play ("transform");

         rigidbody.AddForce (Vector3.down * jumpSpeed);
         rigidbody.mass = 3;
         rigidbody.drag = 0;
         rigidbody.useGravity = true;

         isJetMode = false;

          isRobotMode = true;

         print ("Gravity is turned on ");
     }
 }

 void RobotMove()
 {
     float translation = Input.GetAxis("Vertical") * flightspeed;
     float rotation = Input.GetAxis("Horizontal") * flightrotationSpeed;
     translation *= Time.deltaTime;
     rotation *= Time.deltaTime;
     transform.Translate(0, 0, translation);
     transform.Rotate(0, rotation, 0);

 }


 void VulcanAnim()
 {

     if (Input.GetAxis ("Vertical") >= 1.0f) //forward
     {
         GetComponent<Animation> ().Stop ("idle");
         anim.CrossFade ("run", 0.2f);


     }

     if (Input.GetAxis ("Vertical") <= -1.0f) //backwards
     {
         GetComponent<Animation> ().Stop ("idle");
         anim ["run"].speed = -1.0f; // reverse run anim
         print ("Runningbackward");


     } 

     else if (Input.GetAxis ("Horizontal") <= -1.0f)
     {
         GetComponent<Animation> ().Stop ("idle");
         anim.CrossFade ("strafeLeft", 0.2f);
     
     }

     else if (Input.GetAxis ("Horizontal") >= 1.0f) 
     {
         GetComponent<Animation> ().Stop ("idle");
         anim.CrossFade ("strafeRight", 0.2f);
     
     } 

     else if (Input.GetMouseButtonDown (1))
     {
         anim.CrossFade ("transform", 0.2f);
         GetComponent<Animation> ().Stop ("idle");

     } 

     else
     {
         anim.CrossFade ("idle", 0.2f);
     }


 }

     


     


 


 void idleEnded()
 {
     idleAnim = false;
 }

 void jumpEnded()
 {
     jumpAnim = false;
 }

 void runEnded()
 {
     runAnim = false;
 }
     
 void strafeleftEnded()
 {
     strafeleftAnim = false;
 }

 void straferightEnded()
 {
     straferightAnim = false;
 }

 void transformEnded()
 {
     transformAnim = false;
 }

 void walkEnded()
 {
     walkAnim = false;
 }


}

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

2 Replies

· Add your reply
  • Sort: 
avatar image
0

Answer by sisse008 · Dec 13, 2016 at 01:23 AM

if your character moves to another animation after finishing current one than its because of the hierarchy in the Animator Controller. can you show us a screen shot of it?

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
avatar image
0

Answer by Numonic · Dec 13, 2016 at 04:09 PM

@ Sisse008 Sure but I've just yesterday tried using the Animator in Unity which I was using the Legacy. Figured I try the new one out and see if I can get better results cause of it's robust nature and power. I did get a better result but it's not exactly how I would like it. You see the character runs, idles, jumps and transforms.
The character will have more animations but these are the most important and transformation seems to give me most of the heartache. I have the character transform and lift up and be in Jetmode and when I press the button again to switch animations he doesn't come down fast enough, which i know is a rigidbody issue and just a simple setting, but as soon as he lands he stays in jetmode and doesn't return fast enough to robot mode. Also thanks for the reply. :) I also revamped the character controller code to tailer more of the Animator in Unity. Which by the way is absolutely awesome. Here is the updated code alt text

using UnityEngine; using System.Collections;

public class PlayerAnimatorTest : MonoBehaviour {

 public float flightspeed = 6.0F;
 public float flightrotationSpeed = 100.0F;

 public float speed = 60.0f;
 public float jumpSpeed = 700.0f;

 public AudioClip robotTransforming = null;
 public AudioClip robotFootsteps = null;



 Animator anim;

 Rigidbody rigidbody;



 // Use this for initialization
 void Awake () 
 {
     anim = GetComponent<Animator> ();
     rigidbody = GetComponent<Rigidbody> ();


 }
 
 // Update is called once per frame
 void FixedUpdate () 
 {
     RobotMove ();
     Jump ();
     RobotMode ();


     

 }
     
 void RobotMove()
 {
     float translation = Input.GetAxis("Vertical") * flightspeed;
     float rotation = Input.GetAxis("Horizontal") * flightrotationSpeed;
     translation *= Time.deltaTime;
     rotation *= Time.deltaTime;
     transform.Translate(0, 0, translation);
     transform.Rotate(0, rotation, 0);

     if (translation != 0) //forwards and backwards movement with anim
     {
         anim.SetBool ("isRunning", true);
     } else
     {
         anim.SetBool ("isRunning", false);
     }
 }


 void Jump()
 {
     if (Input.GetButtonDown ("Jump")) 
     {
         anim.SetTrigger ("isJumping");
         rigidbody.AddForce (Vector3.up * jumpSpeed);
     }
 }

 void RobotMode()
 {
     ////////MouseInput//////////////////////////////////////////
     if (Input.GetMouseButtonDown (1)) 
     { 
         anim.SetBool ("isTransform", true);
         anim.SetBool ("isIdle", false);
     
         rigidbody.AddForce (Vector3.up * jumpSpeed);
         rigidbody.mass = 1;
         rigidbody.drag = 0;
         rigidbody.useGravity = false;

     }
         
         if (Input.GetMouseButtonUp (1) )
     
         {
             anim.SetBool ("isTransform", true);
             anim.SetBool ("isIdle", true);
             rigidbody.AddForce (Vector3.down * jumpSpeed);
             rigidbody.AddForce (Vector3.forward  * speed);
             rigidbody.mass = 4;
             rigidbody.drag = 0;
             rigidbody.useGravity = true;
             Debug.Log ("We are going down");
         }
     ////////MouseInput//////////////////////////////////////////

     ////////////////Joystick Input//////////////////////////////////
     if(Input.GetKeyDown(KeyCode.JoystickButton0))
     {
         anim.SetBool ("isTransform", true);
         anim.SetBool ("isIdle", false);
         rigidbody.AddForce (Vector3.up * jumpSpeed);
         rigidbody.mass = 1;
         rigidbody.drag = 0;
         rigidbody.useGravity = false;
     
         Debug.Log("I am pressing button0 on controller and going up");
     }

     if (Input.GetKeyUp (KeyCode.JoystickButton0)) 
     {
         anim.SetBool ("isTransform", true);
         anim.SetBool ("isIdle", true);
         rigidbody.AddForce (Vector3.down * jumpSpeed);
         rigidbody.mass = 4;
         rigidbody.drag = 0;
         rigidbody.useGravity = true;
     
         Debug.Log("I am pressing button0 on controller, and going down");
     }
     /////////////////////////////////////////////////////////////////////////////////////////        
     }
   
    

 

  

}


vulcananimator.jpg (176.9 kB)
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

5 People are following this question.

avatar image avatar image avatar image avatar image avatar image

Related Questions

Google Play Games Services process reward data? C# 0 Answers

Scriptable object sub-classes list 1 Answer

2d game question boxes 0 Answers

Hi, Using quest2. have a flickering issue 0 Answers

PlayGamesPlatform.Instance.Quests.ShowAllQuestsUI 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