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 Medusa-Zenovka · Apr 26, 2015 at 09:47 PM · scripting problemnavmeshnavmeshagent

Mesh as Navmesh?

Is it possible to use a mesh of a moveable object (e.g. platform, spaceship) as navmesh? All I need is a way to put a mesh into an array of local positions so child objects can move like they would on a baked navmesh. I would like to use unitys NavMeshAgent if possible.

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 termway · Apr 27, 2015 at 11:39 AM

Sadly navmesh are limited, so I don't think it's possible right now. But as a workaround you can apply a translation offset to the renderer of your navmesh agent. Here the code I used for my agents on a moving boat using navmesh. The code below manage only one moving platform and modification are required to a more advance navigation.

 //Put on your moving platform
 public class NavMeshDynamic : MonoBehaviour 
 {
     protected Vector3 initialPosition;
     protected Quaternion initialRotation;
 
     // Use this for initialization
     void Awake ()
     {
         initialPosition = transform.position;
         initialRotation = transform.rotation;
     }
 
     public Vector3 getOffsetPosition()
     {
         return transform.position - initialPosition;
     }
 
     public Quaternion getOffsetRotation()
     {
         return transform.rotation * Quaternion.Inverse(initialRotation);
     }
 
     public Vector3 getCorrectedPosition(Vector3 position)
     {
         return position + (transform.position - initialPosition);
     }
 
     public Quaternion getCorrectedRotation(Quaternion rotation)
     {
         return rotation * transform.rotation * Quaternion.Inverse(initialRotation);
     }
 
     public Vector3 getInitialPosition()
     {
         return initialPosition;
     }
 
     public Quaternion getInitialRotation()
     {
         return initialRotation;
     }
 }

 //Put on your renderer (should be child of your navmesh agent)
 public class NavMeshOffset : MonoBehaviour
 {
     public NavMeshDynamic navMeshDynamic;
     public GameObject objectToMove;
 
     protected Quaternion initialObjectRotation;
 
     void Awake()
     {
         initialObjectRotation = objectToMove.transform.rotation;
     }
 
     void LateUpdate() 
     {
         //Correct position from object rotation
         Vector3 offsetDirection = objectToMove.transform.position - navMeshDynamic.getInitialPosition();
         Vector3 offsetDirectionRotated = navMeshDynamic.getOffsetRotation() * offsetDirection;
         transform.position = navMeshDynamic.transform.position + offsetDirectionRotated;
         transform.rotation = objectToMove.transform.rotation *  navMeshDynamic.getOffsetRotation();
     }
 }

Here my hierachy :

  • boat (NavMeshDynamic)

  • agent (NavMeshAgent)
    • offset (NavMeshOffset: objectToMove : agent)
      • rig

    • skinrenderer

Hope it's help you.

Comment
Add comment · Show 1 · 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 Medusa-Zenovka · Apr 29, 2015 at 02:43 AM 0
Share

Thanks, it helped alot. :)

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

i cant acces the navmesh surface 0 Answers

How to have a script temporarily take control of a NavMeshAgent? 1 Answer

Making a queue for NavMeshAgents 0 Answers

How to Calculate NavMeshAgent Paths Quicker 1 Answer

Make NavMesh move to random positions 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