• 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 OctoSloths · Nov 07, 2015 at 07:28 PM · rotationainavmeshnavmeshagentrotation axis

Keep AI from flipping?

I have my AI set up with a Navmesh Agent and set up so that if the player is within a certain range, the AI targets the player and walks towards them. When this happens my AI occasionally collides with static objects causing it to tip on it's x axis. Is there anyway to either reset the rotation of the AI when it flips, or keep the X axis constantly at 0?

I had something previously checking the AI's rotation, and if it changed to anything but 0, to set the rotation back to 0 but it messed up the entire rotation of the AI causing it to not rotate in the direction it was moving in.

Thanks for any help!

EDIT I've noticed this is more of a problem with the AI flipping in general, not just on the x axis. Is there anyway to normalize the rotation of a Navmesh Agent? To keep it from flipping anytime it collides with another object.

Comment
Add comment · Show 1
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 SSStreetFighter · Dec 22, 2020 at 08:38 AM 0
Share

What should I do if I am trying to rotate an object on the x-axis with a navmesh. I need my soldier to rotate 90 degrees on the x so he can lay in the prone, and I need the navmesh so he can move. I actually got him to rotate 90 using the animator. But after that the whole scene breaks.

1 Reply

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

Answer by Le-Pampelmuse · Nov 07, 2015 at 09:23 PM

A NavMeshAgent itself alyways stays upright. It will never rotate around X or Z. http://docs.unity3d.com/Manual/class-NavMeshAgent.html

I assume you use some mesh or skinned mesh as a character that is parented to your AI. If you attached a collider to that as well, and it has a rigidbody attached, this might be the problem. Check all rotation boxes in the rigidbody section, this will prevent it from freely rotating "inside" the AI Object.

If you generally want to restrict the rotation of any transform with a rigidbody inside another, attach a new script with this or include it in any script already attached:

 void Update()
 {
    transform.localEulerAngles = Vector3.zero;
 }

This will always keep the local transform rotation (the rotation inside another transform) at 0,0,0 like you would set in the inspector aswell.
More Info: http://docs.unity3d.com/ScriptReference/Transform.html

I guess you used transform.rotation in the solution you mentioned in the question, but that uses World Space.

Comment
Add comment · Show 2 · 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 OctoSloths · Nov 07, 2015 at 09:55 PM 0
Share

Exactly what I needed! Thank you so much. $$anonymous$$y issue was the rigidbody's rotation as you stated in your answer.

avatar image Le-Pampelmuse OctoSloths · Nov 07, 2015 at 10:09 PM 0
Share

No problem at all! :D

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.

Welcome to Unity Answers

If you’re new to Unity Answers, please check our User Guide to help you navigate through our website and refer to our FAQ for more information.

Before posting, make sure to check out our Knowledge Base for commonly asked Unity questions.

Check our Moderator Guidelines if you’re a new moderator and want to work together in an effort to improve Unity Answers and support our users.

Follow this Question

Answers Answers and Comments

47 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 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

NavMeshAgent resume original position and facing direction C# 0 Answers

Can you randomise a Navmesh agents rotation 1 Answer

Need some help with Navmesh agents backing off from player / circling player please. 0 Answers

Split Rotation and Moving of a NavMeshAgent 1 Answer

NavMesh error in Android build. Can only be called on an active agent that has been placed on a NavMesh 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