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 RealMTG · Feb 06, 2015 at 10:58 PM · rotationmecanimpathfindingastar

A* Pathfinding with mecanim and rotation

Hi!

So basically I need help to make some AI with arongranberg's A* pathfinding project. I can not find a lot of documentation about this so I can't figure out how to make a good AI. I followed the get started tutorial but the AI functions very poorly. My main questions is how I can use mecanim and rotating in the direction it is walking in. The script from the documentation uses Character Controller with Simple move.

So any links to any good tutorials or documentation about this really helps!

If you want to see my code, simply look at the code here: http://arongranberg.com/astar/docs/_astar_a_i_8cs-example.php It is pretty much the same.

Thanks in advance!

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 FireHawkX · Nov 21, 2016 at 07:19 PM 0
Share

I am also currently in the same exact situation and going from 1 thread to the next hoping for any kind of answer...

Since yours is from 2015, have you found a solution since then?

The characters with the "Controller" all go haywire and glitch-rotate all over the place ins$$anonymous$$d of "focusing" towards their objective/waypoint...

Would love to find an actual solution for this... (will keep this bookmarked and come back and post an answer should I manage to find or create one)

avatar image RealMTG FireHawkX · Nov 21, 2016 at 07:24 PM 0
Share

I'm sorry to tell you that I never got anywhere with that. I don't even remember what project this was for. But I would suspect you could do something like getting the next waypoint's position and then making it look in that direction, if that is to any help.

1 Reply

· Add your reply
  • Sort: 
avatar image
1

Answer by FireHawkX · Nov 21, 2016 at 08:09 PM

Here is an answer!! :)

     Vector3 relativePos = TARGET.position - transform.position;  
     //replace TARGET with what they should "look at"
     Quaternion rotation = Quaternion.LookRotation(relativePos);
     transform.rotation = rotation;

By adding that code right after the "controller.SimpleMove (dir);" of the AStar Pathfinder, it makes all of the units look at their target at all time!

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 Spartiate0033 · Nov 22, 2016 at 02:35 AM 0
Share

I did something similar to this. I created a custom function in AILerp.cs that would rotate the transform of our transform towards a target transform using a coroutine. $$anonymous$$ind you, this was for 2D.

     IEnumerator RotateTowardsTransformCoroutine(Transform FOV, Transform transformToFace, float rotationSpeed)
     {
         Vector3 previousEuler = new Vector3(0, 0, 0);
         bool run = true;
         while (run)
         {
             RotateTransform(FOV.transform, transformToFace.transform.position - transform.position, rotationSpeed);
 
             if (previousEuler - FOV.transform.eulerAngles == Vector3.zero)
             {
                 run = false;
             }
             else
             {
                 previousEuler = FOV.transform.eulerAngles;
                 yield return null;
             }
         }
     }

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

21 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

Related Questions

Animation works, pathfinding works, but they don't work together. 1 Answer

Look rotation makes sudden changes 1 Answer

How to rotate object to face toward the path using Astar pathfinding? 0 Answers

Top-down character running animation based on facing direction 0 Answers

A* PathFinding Radius sphere 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