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 GreenTraveler · Mar 28, 2017 at 07:08 AM · unity 5mecanimnavmeshagentclick to move

Click to move, navAgent and mecanim = animation playing too early

 using System.Collections;
 using System.Collections.Generic;
 using UnityEngine;
 using UnityEngine.AI;
 using UnityEngine.UI;
 
 public class ClickToPickup : MonoBehaviour
 {
     private Animator anim;
     private NavMeshAgent farmBoy;
     private bool walking;
     private bool piggyClicked;
     
     void Awake()
     {
         anim = GetComponent<Animator>();
         farmBoy = GetComponent<NavMeshAgent>();
     }
 
     void Update()
     {
         Ray ray = Camera.main.ScreenPointToRay(Input.mousePosition);
         RaycastHit hit;
         if (Input.GetMouseButtonDown(0) && !UnityEngine.EventSystems.EventSystem.current.IsPointerOverGameObject())
         {
             if (Physics.Raycast(ray, out hit, Mathf.Infinity))
             {
                 if (hit.collider.tag == ("Piggy"))   
                 {
                     piggyClicked = true;
                     farmBoy.destination = hit.transform.position;
                 }
                 else
                 {
                     piggyClicked = false;
                     farmBoy.destination = hit.point;
                   // farmBoy.Resume();
                 }
             }
         }
 
         
 
         if (farmBoy.remainingDistance <= farmBoy.stoppingDistance)
         {
              walking = false;
         }
         else
         {
              walking = true;
             
         }
         anim.SetBool("isWalking", walking);
 
         if (piggyClicked)
         {
             PickUp();
         }
     }
 
      void PickUp()
      {
             anim.SetBool("pickupPiggy", true);
             anim.SetBool("isHolding", true);
      }
 }

Greetings.. so the the setup i have is 6 animations Idle, Run, PickupPiggy, HoldPiggy(idle), CarryPiggy, PutdownPiggy.

alt text

farmBoy is supposed to run anywhere i Left click on the ground(plane) and if i Left click on a piggy he should look at the pig and run to it then do the PickupPiggy animation and go into the HoldPiggy Idle state and when i click on the ground now he should play the CarryPiggy animation until i click on the spot i want to drop the piggys off at

i havent tried to parent the pigs to my guy yet until i can get the animations working

i used the script from the unity tutorial Click to Move and mostly its working when i click on the ground plane farmboy plays the Run animation and then stops at the spot i clicked and goes into Idle just fine, but when i click on a piggy farmBoy does the pickup animation right away and then does the carry animation to the piggy and goes into HoldPiggy idle animation like he should, i need some help please..

everything seems to be working except he plays the PickupPiggy animation before he gets to the piggy once thats all working ill need to figure out how to drop the pigs off in the pen a spot on the map

other issues that are coming soon are the distance to the pigs is wrong he runs right on top of em instead of next to them.. the speed when he is carrying a pig needs to be slower than when hes not holding one

any help to why it plays the animation first before running to the pig would be wonderful

ive tried if statements in the void PickUp()

" if (farmBoy.remainingDistance <= farmBoy.stoppingDistance) { anim.SetBool("pickupPiggy", true); anim.SetBool("isHolding", true); } " but it didnt change anything

btw i can click the bools in the animator and he pickups and putsdown and carrys just the way i want

thanks

farmboyanimator.png (28.0 kB)
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

0 Replies

· Add your reply
  • Sort: 

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

object position changed in play mode after adding animation to animator component 0 Answers

I can't setting at once ModelImporter.sourceAvatar in script. 1 Answer

Any idea why my animation isn't working? 0 Answers

Multiple NavmeshAgents waiting each other to move to destination?? 1 Answer

Mecanim Example Scenes import warnings. 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