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
-1
Question by Godahl · Jan 31, 2017 at 08:34 PM · vector3navmeshnavmeshagent

Get Navagent to move upward off the navmesh

I'm making a game with some civilians controlled by navagents on a navmesh, and periodically I need them to be abducted by flying saucers and move off the Navmesh directly upward. However, when I disable the navagent component to move it up, the gameobject continues to move in the direction it was last moving when the navagent was disabled, so instead of moving directly upward to the flying saucer, it moves up diagonally away from it.

I tried adding the Stop() method before disabling the navmesh, but that gives me the error message "'Stop' can only be called on an active navagent that has been placed on a navmesh."

Here's a code snippet that seems to be the problem. Anyone have any ideas?

 if (captured == true)
             {
                 agent.SetDestination(flyingSaucer.transform.position);
                 agent.velocity = Vector3.zero;
                 agent.speed = 0;
                 agent.Stop();
                 agent.enabled = false;
                 this.GetComponent<Rigidbody>().useGravity = false;
                 transform.position = Vector3.MoveTowards(transform.position, flyingSaucer.transform.position, abductedSpeed * Time.deltaTime);
             }

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 FortisVenaliter · Jan 31, 2017 at 08:39 PM 0
Share

Is that in update, being called every frame? Or only when the trigger is first hit?

If it's being called every frame, then you are calling Stop() on an inactive Nav$$anonymous$$eshAgent.

avatar image Godahl · Feb 01, 2017 at 09:25 AM 0
Share

@FortisVenaliter I was calling it on update, but I just fixed that and I'm still having the same trouble. Here's my update code: private void Update() { //normal movvement when citizen is not abducted. if (captured == false) {

             if (target != null)
                 agent.SetDestination(targets[targetNum].transform.position);

             if (agent.remainingDistance > agent.stoppingDistance)
             {
                 character.$$anonymous$$ove(agent.desiredVelocity, false, false);

             }
             else
             {
                 if (targetNum <= targets.Length - 1)
                 {
                     targetNum++;
                     agent.SetDestination(targets[targetNum].transform.position);
                 }
                 else
                     targetNum = 0;
             }

         }
         //on trigger with flying saucer beam, navagent is turned off and this causes the citizen to rise upward
         else if (captured == true)
         {
             transform.position = Vector3.$$anonymous$$oveTowards(transform.position, flyingSaucer.transform.position, abductedSpeed * Time.deltaTime);
         }
     }

And here's the method that is called by the collider on the other object on collision (the citizen has a box collider and the other has a trigger collider, so I had to have this method called by the other object:

         //this is called by abductscript on its ontriggerenter().
         public void Abducted()
         {
             agent.SetDestination(flyingSaucer.transform.position);
             agent.velocity = Vector3.zero;
             agent.speed = 0;
             agent.Stop();
             agent.enabled = false;
             this.GetComponent<Rigidbody>().useGravity = false;
             captured = true;
             
         }

avatar image FortisVenaliter Godahl · Feb 01, 2017 at 06:43 PM 0
Share

Okay, that looks like it should work, generally. I would remove the SetDestination call in the Abducted() function, because it's redundant when you're disabling the component immediately afterward.

But what is the problem you're seeing now?

1 Reply

· Add your reply
  • Sort: 
avatar image
-1

Answer by IgorAherne · Jan 31, 2017 at 11:57 PM

Use offMeshLink

Here are a few functions which you can use, in particular inspect "Variables" and "Public Functions"

Also, look into NavMeshAgent API, to be specific, CTRL+F ---> have a look at anything with "offMeshLink" inside of it

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

6 People are following this question.

avatar image avatar image avatar image avatar image avatar image avatar image

Related Questions

Can I find the layer of a NavMeshPath corner? 0 Answers

Angle Between vectors in Navigation Mesh 1 Answer

Enlarge the NavMesh paths my player has to follow 1 Answer

Multiple agent types problem - NavMesh 0 Answers

Navmesh sometimes falling through world when enabled 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