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 /
  • Help Room /
avatar image
0
Question by sskenth · Sep 22, 2016 at 05:01 PM · bugphysics2danimator controllerinheritance

[VIDEO] Animator controller stopping physics? inheritance problem or bug?

Hi

I'm fairly new to Unity, I've come across an odd bug where my hero is no longer falling or reacting to gravity while the animator component is attached. This occurred after I added a wolf child object to a parent class called Character also shared by the hero.

The odd thing is, if I remove/delete the wolf from the game scene and hierarchy the bug still persists, so I dont believe its to do with inheritance, but I may be wrong. If I remove the animator, the character reacts to physics, but immediately returns to his original position stuck in midair once I re-add the animator component.

Here's a video demonstrating the issue, and below is a bunch of code from the Character.cs(parent class)

I'm hoping its just a silly mistake on my part, but I cant seem to spot it. Also please note I'm using Unity 5.4.1 and I've also tried it with the 5.5 beta.

Kind Regards

Sat

 using UnityEngine;
 using System.Collections;
 
 public class Character : MonoBehaviour {
 
     //protected Animator anim;
 
 
 
     public float speedX =6.0f;
     protected float speed;
     public float punchSpeedX;
     public float jumpSpeedY;
     public int TotalGroundObjectsTouching;
     protected bool FacingRight, Jumping, Moving;
 
     public int JumpLimit, HasJumped;
 
     public bool isPunching;
     Rigidbody2D rb;
 
     public Animator MyAnimator { get; private set; }
 
     // Use this for initialization
     public virtual void Start () {
  
         MyAnimator = GetComponent<Animator>();
         rb = GetComponent<Rigidbody2D>();
         FacingRight = true;
         TotalGroundObjectsTouching=0;
         Moving = false;
 
         punchSpeedX= 1.5f;
 
         isPunching = false;
     
     }
     
     // Update is called once per frame
     public virtual void Update () {
         //Debug.Log("SPEED IS "+speed);
         MovePlayer(speed);
     }
 
     void Flip()
     {
 
             Vector3 temp = transform.localScale;
             temp.x *=-1;
             transform.localScale = temp;
 
     }
 
 
     public void touchedGround(int collCount)
     {
         HasJumped=0;
 
         TotalGroundObjectsTouching = collCount;
         Jumping = false;
         MyAnimator.SetInteger("TotalGroundObjectsTouching",TotalGroundObjectsTouching);
     }
 
 
     public virtual void setGroundObjects(int amountTouching)
     {
         if( HasJumped ==0 && TotalGroundObjectsTouching==1)
         {
             //HasJumped++;
         }
         
         TotalGroundObjectsTouching=amountTouching;
 
         MyAnimator.SetInteger("TotalGroundObjectsTouching",TotalGroundObjectsTouching);
     }
 
     protected void MovePlayer(float playerSpeed)
     {
         Debug.Log("move player "+playerSpeed);
 
         if(isPunching==false)
         {
             rb.velocity = new Vector3 (playerSpeed, rb.velocity.y,0);
             //rb.velocity = new Vector3 (speed, Mathf.Clamp(rb.velocity.y, -18.0F, 20.0F) ,0);
 
 
         }else{
 
                 int direction;
                 if(FacingRight==true)
                 {
                     direction= 1;
                 }else{
                     direction=-1;
                 }
                 rb.velocity = new Vector3 ((speedX*punchSpeedX)*direction, 0,0);
 
         }
 
     }
 
 
 
     public virtual void MoveLeft()
     {
         //if(isPunching==false)
         //{
             //moveWhilePunch="false";
             Moving = true;
             //LeftMoveKeyDown=true;
             speed = -speedX;
             if(FacingRight==true)
             {
                 FacingRight = false;
                 Flip();
 
             }
         //}else{
             //moveWhilePunch = "left";
         //}
     }
 
     public virtual void MoveRight()
     {
         //if(isPunching==false)
         //{
             //moveWhilePunch="false";
             Moving = true;
             //RightMoveKeyDown=true;
             speed = speedX;
             if(FacingRight==false)
             {
                 FacingRight = true;
                 Flip();
 
             }
         //}else{
             //moveWhilePunch="right";
         //}
     }
 
     public void Punch()
     {
         //Debug.Log("Punch event");
         isPunching=true;
         MyAnimator.SetBool("isAttacking",isPunching);
 
     }
     public void StopPunching() // this is called by the HeroPunchingState.cs at the end of punch animation
     {
         //Debug.Log("STOP PUNCHING");
         isPunching=false;
         ///punchStarted=false;
         MyAnimator.SetBool("isAttacking",false);
 
     }
 
     public void StopMoving()
 
     {
     
         if(isPunching==false)
         {
             Moving = false;
             speed = 0;
         }
 
     }
 
     public Vector2 GetDirection()
     {
 
         return FacingRight ? Vector2.right : Vector2.left;
     }
 
     public bool IsFacingRight()
     {
 
         return FacingRight;
     }
 
     public void Jump()
     {
         if(HasJumped<JumpLimit){
             
             HasJumped++;
             Jumping=true;
             //rb.AddForce(new Vector2 (rb.velocity.x, jumpSpeedY));
             rb.velocity= new Vector2 (rb.velocity.x, jumpSpeedY);
         }
     }
 
 }
 


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 sskenth · Sep 23, 2016 at 03:51 AM

So I managed to solve it, turns out there was nothing wrong with the code, but the animator for my character had a parameter in there, although I couldn't see that actually effecting anything, once I deleted it things worked again.
Very odd since the parameter wasnt being used, but never mind, all is well!

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

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

Related Questions

Inspector in animator is not showing. 1 Answer

animator.play() not working anymore 0 Answers

Physics2D.DestroyShapes() has an enormous impact on performances even when very few Physics Shapes Exist 0 Answers

How to stop the animation before the object got disabled. 0 Answers

Can't add condition to a transition in animator controller 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