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
1
Question by BHS · Sep 23, 2014 at 09:18 PM · rotationraycastnavmeshx axis

How do you rotate a NavMesh object to match the terrain's angle?

Hi,

I'm trying to rotate an object along its X axis that's using a NavMesh component. The AI is already finished and works fine. The problem is that the NavMesh object needs to match the terrain's angle to avoid looking unrealistic like below. The object seems to always stay at 0 degrees regardless of it being rotated.

I'm using the code below (JS) to get the angle of the front and back of the model using raycasts which then aligns the model according to the angle of the terrain. The problem is that for some reason Unity will not let me rotate an object that's using a NavMesh component and I'm not sure why. I hope I'm mistaken and it's something on my part.

I've tested this out with an object not using NavMesh and it works perfectly fine so I'm not really sure what the issue is. If anyone can point me in the right direction it would be greatly appreciated.

 function FixedUpdate()
 {
     var hit: RaycastHit;
     if (Physics.Raycast(transform.position + transform.forward, Vector3.down, hit)){
         var fHit = hit.point; // get the point where the front ray hits the ground
         if (Physics.Raycast(transform.position - transform.forward, Vector3.down, hit)){
             var bHit = hit.point; // get the back hit point
             transform.forward = fHit - bHit; // align the object to these points
         }
     }
 }

alt text

issue.png (451.7 kB)
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 jpthek9 · Oct 12, 2014 at 12:55 PM 0
Share

Bump, there's gotta be a way!

I'm thinkign somewhere along the lines of making the mesh seperate from the navmeshagent and raycast down with the mesh... but so much plumbing :(

avatar image jacupiri · Sep 04, 2016 at 12:36 PM 0
Share

I've got the same problem on my game. What is annoying me is that the archer's AI need him to lookAt the target, but when Nav$$anonymous$$eshAgent is on, it doesn't let the archer gameObject rotate around the Y axis to look uphill or downhill.

So the archer simply won't shoot...

1 Reply

· Add your reply
  • Sort: 
avatar image
0

Answer by lastrymac · Jan 08, 2015 at 02:36 PM

Make sure your model is on a child, and orient that, don't orient the navmeshagent. Try to use good organizational skills. You don't want 30 components on one gameobject, finding anything in the inspector would be a pain. Controls should be the root, housing your AI and such, your main controls for the character. Underneath that is where you want your "Make it look pretty" stuff. Animators, particle systems, such as dirt being kicked up. Sorry for the late response. I just found this after searching for something else.

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

28 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

Related Questions

How does LookRotation work in relation to ray cast? 1 Answer

Unity Rotate Raycast on Quaternion 1 Answer

Player's last location as a Transform 1 Answer

Raycasting from object rotation? 1 Answer

click to move workig script!! but pls help with rotation!! :( 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