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 catlord1993 · Oct 23, 2015 at 12:24 PM · 2d sprites2d animationwaypoint

Making a 2d sprite play its animation at given waypoint.

Hello, everyone. I'm still quite a beginner in coding.

I'm trying to make 2.5D like game as a practice project.

I'm trying to get my 2d sprite character idle animation to play after its moving animation done reaching to the given way point.

This is the code I've done so far:

 public Transform[] points;
  
 private int destPoint;
 
 private NavMeshAgent agent;
 
 private Animator anim;
 
 bool _isWalkingUp = false;
 
 const int STATE_IDLEFRONT = 0;
 const int STATE_WALKFRONT = 1;
 
     void moveThere()
     {
         if (_isWalkingUp == false) {
 
             agent.destination = points [0].position;
             changeState (STATE_WALKFRONT);
             _isWalkingUp = true;
 
         } else if (_isWalkingUp == true) {
             changeState(STATE_IDLEFRONT);
         }
 
 
     }
     
 
     void changeState(int state){
         if (_currentAnimationState == state)
             return;
         switch (state) {
 
         case STATE_IDLEFRONT:
             anim.SetInteger ("state" , STATE_IDLEFRONT);
             break;
 
 
         case STATE_WALKFRONT:
             anim.SetInteger ("state" , STATE_WALKFRONT);
             break;
 
         }
         _currentAnimationState = state;
     }
 

Its on this part here where my character does its front move animation and then reaches its waypoint but my idle animation doesn't play it from there. Even the debug.log there is a no show. Can anyone help me?

 if (_isWalkingUp == false) 
 {
              agent.destination = points [0].position;
              changeState (STATE_WALKFRONT);
              Debug.Log ("Walking There");
              _isWalkingUp = true;
  
          } else if (_isWalkingUp == true) {
              Debug.Log("Meow");
              changeState(STATE_IDLEFRONT);
          }
 
 }

Comment
Add comment · Show 3
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 DiegoSLTS · Oct 23, 2015 at 01:04 PM 0
Share

Share an image of the animator and the transitions you used, please

avatar image catlord1993 DiegoSLTS · Oct 23, 2015 at 02:09 PM 0
Share

Animator: alt text

animator-w-transitions.png (101.9 kB)
avatar image catlord1993 DiegoSLTS · Oct 23, 2015 at 02:11 PM 0
Share

Transitions: alt text

transitions.png (42.3 kB)

1 Reply

· Add your reply
  • Sort: 
avatar image
1

Answer by DiegoSLTS · Oct 23, 2015 at 05:33 PM

I think you're missing a like to set _IsWalkingUp back to false.

 Debug.Log("Meow");
 changeState(STATE_IDLEFRONT);
 _IsWalkingOn = false;
Comment
Add comment · Show 5 · 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 catlord1993 · Oct 23, 2015 at 10:47 PM 0
Share

Sadly, it didn't work. It seems like my else if statement isn't being read at all. Which I'm very confused about now.

avatar image DiegoSLTS catlord1993 · Oct 24, 2015 at 12:05 AM 0
Share

How is the "moveThere" method called? Share the code or explain a bit more how it's used. Also, are you sure _isWalkingUp is not being changed somwhere else?

avatar image catlord1993 DiegoSLTS · Oct 24, 2015 at 12:37 AM 0
Share

Its on my void awake. I forgot to add this part. and No, the _isWalkingUp is only called at moveThere() function.

 void Awake() {
 
         anim = this.GetComponent<Animator>();
         agent = GetComponent<Nav$$anonymous$$eshAgent> ();
         agent.autoBraking = true;
 

         moveThere ();
 
     
     }
Show more comments

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

The sprite editor won't let me slice 7 Answers

Questions about 2D rigging and animationtransition. 0 Answers

Adding Clothes to a 2D Skelatal Animated Character 1 Answer

How to get a customizatble sprite to animate alternate parts?,How do I get my characters eyes to move when I push play? 0 Answers

Issue with Animating MultiPart 2D Character with RigidBodies 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