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 Philxx · Nov 24, 2016 at 10:17 PM · animationanimatoranimation controller

Grid movement bug.

I have a 2D grid and I move from one place to the next and if I let go of the movement key, the player will continue moving untill he reaches the closest grid block. When I release the arrow key and the player hasn't reached the block yet, the animation changes to facing downward until he reaches the next block. How do I make it so that he continues his animation until he reaches the block?

This is my code. https://imgur.com/a/m665r

I believe the problem is in this part of the code.

 // Move there
     transform.position = Vector3.MoveTowards(transform.position, pos, Time.deltaTime * speed);
     if(transform.position == Vector3.MoveTowards(transform.position, pos, Time.deltaTime * speed))
     {
         playerMoving = false;
     }

I need to somehow add a way of keeping the animation playing until reaching the next grid block and then change it to the direction the player is facing.

I also get this error:

difference in effective length between states is too big. transition preview will be disabled.

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 hexagonius · Nov 24, 2016 at 10:25 PM

the actual move and the check ate the same code, so it's basically always true. Check for the final position

 if(transform.position == pos)
      {
          playerMoving = false;
      }
Comment
Add comment · Show 3 · 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 Philxx · Nov 24, 2016 at 10:40 PM 0
Share

Thanks. It's a lot shorter and easier to read. $$anonymous$$y character still has the animation problem though.

https://imgur.com/a/$$anonymous$$OP4Y

The closer i am to the grid block, the shorter the downward animation is but it's still there and I don't know why it's there or how to get rid of it.

avatar image hexagonius Philxx · Nov 25, 2016 at 10:02 AM 0
Share

well, you mapped the animator to your input directly. so even though he is making the last steps towards the target, the animatior gets all float set to false, which I guess is then your downward looking idle state.
What I would do is check if the player is on his way first. As long as he just return the whole method and keep moving. AFTER that check, when he has reached it, check for the input while setting your animator according to it. If there's input still, set a new target, which keeps code execution from altering your animator again. So in pseudo code:

     Update
     
     if (!reachedTarget)
     return;
     
     set animator to input
     
     if (input)
     set new target
avatar image Philxx hexagonius · Nov 25, 2016 at 04:43 PM 0
Share

What would that look like in the code? I'm somewhat new to coding and still getting a hold of things.

This is the code I've got so far.

https://imgur.com/a/m665r

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

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

Related Questions

Animation clip doesn't play 1 Answer

How do I know what animation I can transit to in the animator, from my current animation? 0 Answers

Why is the last frame of the animation not triggering? 0 Answers

How do you make sure that when you land on an object, an animation starts? 0 Answers

Animation from child object overrided by its parent and won't show in game window 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