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 Zedock · Mar 09, 2015 at 08:17 AM · animationanimatorprogramming

There is a problem with the code, possibly the animator as well... Please help?

I think the problem may be with the animator but I couldn't be overly sure as I am a beginner. but just in case I have included the code in the space below. The problem is that my character will not switch animations at the correct time, if more screen shots are needed then please specify what parts of the program you need

Animator Screenshots:

http://www.filedropper.com/screenshot2015-03-03at92640pm_1

http://www.filedropper.com/screenshot2015-03-03at92709pm_1

http://www.filedropper.com/screenshot2015-03-03at92723pm_1

http://www.filedropper.com/screenshot2015-03-03at92730pm_1

http://www.filedropper.com/screenshot2015-03-03at92738pm_1

using UnityEngine; using System.Collections;

public class Hedgehog : MonoBehaviour {

 private Rigidbody2D _myRigidBody;
 private Animator _animator;
 private bool _facingRight = true;
 private bool _canJump;
 public float speed;
 public Transform startPos;
 public Transform endPos;
 public LayerMask groundLayer;
 public float speedInc;

 void Start () 
 {
     _myRigidBody = this.rigidbody2D;
     _animator = GetComponent<Animator> ();
     _canJump = true;
     speedInc = 0.1f;
 }

 void Update () 
 {
     float move = Input.GetAxisRaw("Horizontal");
     _animator.SetFloat ("Speed", Mathf.Abs(move)); 
     _myRigidBody.velocity = new Vector2 (move * speed, _myRigidBody.velocity.y);



     Debug.Log (speed);
     speed += speedInc * Time.deltaTime;

     if (speedInc >= 10) 
     {
         speedInc = 0;
     }

     if(speed >= 5 && speed <= 9)
     {
         walk ();
     }

     if (speed >= 10) 
     {
         run();
     }
     
     /*RaycastHit2D hitInfo = Physics2D.Linecast (startPos.position, endPos.position, groundLayer.value);
     
     Debug.DrawLine (startPos.position, endPos.position);
     
     
     if (hitInfo.collider != null) 
     {
         _canJump = true;
         _animator.SetBool ("Jump", false);
     }
     
     if (Input.GetKeyDown (KeyCode.Space) && _canJump == true) 
     {
         _animator.SetBool ("Jump", true);
         _myRigidBody.velocity = new Vector2 (_myRigidBody.velocity.x, 10);
         _canJump = false;
     }*/
 }

 void walk()
 {
     float move = Input.GetAxisRaw("Horizontal");
     _animator.SetFloat ("Speed", Mathf.Abs(move)); 
     _myRigidBody.velocity = new Vector2 (move * speed, _myRigidBody.velocity.y);

     if (_facingRight == true && move < 0) 
     {
         _facingRight = false;
         transform.rotation = Quaternion.Euler (transform.rotation.x, 180, transform.rotation.z);
     }
     if (_facingRight == false && move > 0) 
     {
         _facingRight = true;
         transform.rotation = Quaternion.Euler (transform.rotation.x, 0, transform.rotation.z);
     }
 }

 void run()
 {
     float move = Input.GetAxisRaw("Horizontal");
     _animator.SetFloat ("Speed", Mathf.Abs(move)); 
     _myRigidBody.velocity = new Vector2 (move * speed, _myRigidBody.velocity.y);

     if (_facingRight == true && move <= 5) 
     {
         _facingRight = false;
         transform.rotation = Quaternion.Euler (transform.rotation.x, 180, transform.rotation.z);
     }
     if (_facingRight == false && move >= 9) 
     {
         _facingRight = true;
         transform.rotation = Quaternion.Euler (transform.rotation.x, 0, transform.rotation.z);
     }
 }

}

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

Answer by tebandesade · Mar 18, 2015 at 09:59 PM

Have you tried playing around with the options that are of the transition ( Has exit time, TransitionDuration etc) ? Maybe you can play around there and smoothen the animation. Or also changing the values in where each animation begins, as well as the speed.

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

3 People are following this question.

avatar image avatar image avatar image

Related Questions

Multiple Cars not working 1 Answer

Floating boss Hands, can't move bones of hands for attacks 0 Answers

Animator.Rebind didn't work. 1 Answer

How to resume animation where it left off? 3 Answers

Need help with wall cover system(splinter cell like) 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