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 barbe63 · Jan 13, 2015 at 02:31 AM · navmeshagentbackward

Moving Navmesh agents backward

Hello,

I'm trying to move some Navmesh agents backward and i'm getting unsuccessfull for now. The animation is good but my agent is going forward with this backward animation and since we can't put a negative value for speed agent i wonder... How that can be done? What am I missing? Thanks in advance.

Comment
Add comment · Show 4
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 GameVortex · Jan 13, 2015 at 07:51 AM 0
Share

Put the visuals as a child of the NavigationAgent and rotate the visuals on the y axis 180 degrees.

avatar image barbe63 · Jan 13, 2015 at 08:19 AM 0
Share

I tried that method earlier but i dont' want my NPC to rotate around so that doesn't seems to be a nice way unless i'm missing something...

Right now i think I found a better solution (but it's not done yet) using agent.updateRotation=false and then do the rotate myself. I will tell later if it's a good way.

avatar image GameVortex · Jan 13, 2015 at 08:25 AM 0
Share

Yes, that is probably the best way. =)

avatar image Mmmpies · Jan 13, 2015 at 09:03 AM 0
Share

You don't have to use navmesh you can use any other method to move your character backwards. Of course it wouldn't check for walls etc as navmesh would.

3 Replies

· Add your reply
  • Sort: 
avatar image
2

Answer by barbe63 · Jan 13, 2015 at 09:24 AM

Yes!

I found it so for those who are interested, i'm using:

     agent.updateRotation=false; // disable the automatic rotation
          while(condition)
                 {
                     Vector3 direc = Vector3.zero;
                     direc.y = AngleTo360(CalculateYAngle(trans.position, agent.steeringTarget)); // this return an angle between my NPC and the next waypoint of agent from 0 to 360 degrees
         //then i need to prevent the difference from beeing too big (in case one is at 10 and the other 350 for example)
                     if (Mathf.Abs(direc.y-trans.eulerAngles.y)>180)
                     {
                         if(direc.y<180)
                             direc.y+=360;
                         else
                             direc.y-=360;
                     }
                     trans.eulerAngles = Vector3.Lerp(trans.eulerAngles, direc, Time.deltaTime);
                     yield return null;
                 }
     agent.updateRotation=true; //when no longer need to step back then go to normal

Of course if someone has a more efficient way to do this i'm buying :p

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
avatar image
0

Answer by sysmaya · Mar 02, 2017 at 10:42 AM

Disable agent.

Enable animation walkBack.

use transform. translate for move.

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 andrew-lukasik · Dec 11, 2021 at 12:09 PM 0
Share

NavMeshAgent.Move > transform.translate

avatar image
0

Answer by Z0leee87 · Dec 11, 2021 at 05:55 PM

I am a beginner, but i think there is an option for this:

 // from WORLD to LOCAL
 Vector3 inversePos = transform.InverseTransformPoint(inFrontOfMe.transform.position);
 
 // DEF COORDS IN LOCAL
 float locTargetOnX = inversePos.x;
 float locTtargetOnZ = inversePos.z;
 
 // NEGATIVE (local) COORDS
 float negLocTargetOnX = -locTargetOnX;
 float negLocTtargetOnZ = -locTtargetOnZ;
 
 // FROM LOCAL TO WORLD  (works only flat plane because of the Y (I would be glad if you could help))
 Vector3 negativePos = transform.TransformPoint(negLocTargetOnX, 0.0f, negLocTtargetOnZ);
 
 // SET THE OTHERS
 myAgent.speed = 2.0f;
 //myAgent.SetDestination(new Vector3(0,0,0));
 myAgent.SetDestination(negativePos);
 myAgent.isStopped = false;


Sorry for my english...

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

9 People are following this question.

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

Related Questions

Enemy freezes in NavMesh and starts attacking? [Duplicate] 0 Answers

NavMeshPath get path cost 0 Answers

Im terrible at C# but can someone explain to me exaclty whats wrong with my script? 2 Answers

charachters stand next to each other 0 Answers

how to instantiate prefabs around the player but when there is an object in that position it dont instantiate 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