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 Yarden-Raveh · Dec 17, 2013 at 07:42 PM · animationanimatormecanimanimator controllerblend tree

Can't set animator bool to True

I am trying to write a simple point and click movement system. I press a point and my character moves there using navmesh. Everything works. I press a point, a marker is set and my character moves there. There is a small problem with the animation however. First here is the code i am using:

     void Update () {
 
                 if (Input.GetKeyUp(KeyCode.Mouse0)) {
                         ray = characterCamera.ScreenPointToRay (Input.mousePosition);
                         didHit=Physics.Raycast (ray, out hit);
                         if (didHit && hit.collider.tag=="Travel") {
                             anim.SetBool ("Walking",true);
                             Debug.Log ("Walking: true");
                             if (currentMarker!=null){
                                 Destroy (currentMarker);
                             }
                             rayHitPosition=hit.point;
                             currentMarker=Instantiate (Marker,rayHitPosition,Quaternion.Euler (Vector3.zero));
                             agent.destination=rayHitPosition;
                         }
                 }
                 if (agent.remainingDistance<=0)
                 {
                     anim.SetBool ("Walking",false);
                 }
         }

My Walking bool sometimes won't set to true. When i set press my mouse for the first time the bool won't set to true however if i press again WHILE the agent is in motion then the bool will set to true and the animation play. Anything i am missin? Why won't it set the bool on the first click?

Comment
Add comment · Show 2
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 guitarxe · Dec 17, 2013 at 08:08 PM 0
Share

Does RayCast check all collisions within the same frame it is called? I haven't explored raycasts yet, but if it's part of the Physics, then perhaps it only updates on every physics frame, which is not every frame?

To see what's going on, put

Debug.Log(didHit);

Debug.Log(hit.collider.tag);

right under didHit=Physics.Raycast (ray, out hit); , run the game, and see the console.

avatar image Yarden-Raveh · Dec 19, 2013 at 06:11 AM 0
Share

I did, It seems they all update at the same time. Also if the hit.collider.tag wasn't Travel and my didHit not true then my character wouldn't be moving at all.

1 Reply

· Add your reply
  • Sort: 
avatar image
0
Best Answer

Answer by Yarden-Raveh · Dec 19, 2013 at 08:11 PM

Found the answer. The navmeshagent remainingDistance is only calculated after the frame in which the destination was changed. Instead of checking if agent.remainingDistance is 0 I used vector3.distance to calculate the remaining distance manually.

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

17 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

Related Questions

Is there a way to change the WrapMode of all Animations in a Mecanim Animator? 1 Answer

Mecanim Transition-Arrow Pulsing 2 Answers

unity freezes when running sprinting animation 0 Answers

Animation Mecanim - Parts of model displaces after animating 0 Answers

2D: initial sprite idle animation playing too fast upon game initiation until I input movement keys? 1 Answer


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